﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows.Media.Imaging;
using System.Windows.Resources;
using System.Diagnostics;
using System.Threading;
using System.Diagnostics.CodeAnalysis;
using System.Xml.Linq;
using System.Xml;

namespace Delay
{
    public static class LowProfileImageLoader
    {
         public static Stretch ImageStrech=Stretch.Uniform;
        public static PendingCompletion progressPending = null;
         //用于控制图片显示模式
        //只有切回主页面采取拉伸裁剪模式
        public static bool isNonPictureMode = false;
        private const int WorkItemQuantum = 1;
        private static AutoResetEvent WaitUiThread = new AutoResetEvent(false);
        private static readonly Thread _thread = new Thread(WorkerThreadProc);
        private static readonly Queue<PendingRequest> _pendingRequests = new Queue<PendingRequest>();
        private static readonly Queue<IAsyncResult> _pendingResponses = new Queue<IAsyncResult>();
        private static readonly object _syncBlock = new object();
        private static bool _exiting;
        /// <summary>
        /// Gets the value of the Uri to use for providing the contents of the Image's Source property.
        /// </summary>
        /// <param name="obj">Image needing its Source property set.</param>
        /// <returns>Uri to use for providing the contents of the Source property.</returns>
        [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "UriSource is applicable only to Image elements.")]
        public static Uri GetUriSource(DependencyObject obj)
        {
            if (null == obj)
            {
                throw new ArgumentNullException("obj");
            }
            return (Uri)obj.GetValue(UriSourceProperty);
        }
        /// <summary>
        /// Sets the value of the Uri to use for providing the contents of the Image's Source property.
        /// </summary>
        /// <param name="obj">Image needing its Source property set.</param>
        /// <param name="value">Uri to use for providing the contents of the Source property.</param>
        [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "UriSource is applicable only to Image elements.")]
        public static void SetUriSource(DependencyObject obj, Uri value)
        {
            if (null == obj)
            {
                throw new ArgumentNullException("obj");
            }
            obj.SetValue(UriSourceProperty, value);
        }
        /// <summary>
        /// Identifies the UriSource attached DependencyProperty.
        /// </summary>
        public static readonly DependencyProperty UriSourceProperty = DependencyProperty.RegisterAttached(
            "UriSource", typeof(Uri), typeof(LowProfileXmlLoader), new PropertyMetadata(OnUriSourceChanged));
        /// <summary>
        /// Gets or sets a value indicating whether low-profile image loading is enabled.
        /// </summary>
        public static bool IsEnabled { get; set; }
        [SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Justification = "Static constructor performs additional tasks.")]
        static LowProfileImageLoader()
        {
            // Start worker thread
            _thread.Start();
            Application.Current.Exit += new EventHandler(HandleApplicationExit);
            IsEnabled = true;
        }
        private static void HandleApplicationExit(object sender, EventArgs e)
        {
            // Tell worker thread to exit
            _exiting = true;
            if (Monitor.TryEnter(_syncBlock, 100))
            {
                Monitor.Pulse(_syncBlock);
                Monitor.Exit(_syncBlock);
            }
        }
        [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Relevant exceptions don't have a common base class.")]
        private static void WorkerThreadProc(object unused)
        {
            Queue<PendingRequest> pendingRequests = new Queue<PendingRequest>();
            Queue<IAsyncResult> pendingResponses = new Queue<IAsyncResult>();
            while (!_exiting)
            {
                lock (_syncBlock)
                {
                    // Wait for more work if there's nothing left to do
                    if ((0 == _pendingRequests.Count) && (0 == _pendingResponses.Count) && (0 == pendingRequests.Count) && (0 == pendingResponses.Count))
                    {
                        Monitor.Wait(_syncBlock);
                        if (_exiting)
                        {
                            return;
                        }
                    }
                    // Copy work items to private collections
                    while (0 < _pendingRequests.Count)
                    {
                        pendingRequests.Enqueue(_pendingRequests.Dequeue());
                    }
                    while (0 < _pendingResponses.Count)
                    {
                        pendingResponses.Enqueue(_pendingResponses.Dequeue());
                    }
                }
                Queue<PendingCompletion> pendingCompletions = new Queue<PendingCompletion>();
                // Process pending requests
                for (var i = 0; (i < pendingRequests.Count) && (i < WorkItemQuantum) ; i++)
                {
                    var pendingRequest = pendingRequests.Dequeue();
                    //AndreasHammar 2011-01-25: is getting this in the Tre.News app
                     if (pendingRequest.Uri == null) continue;
                     if (pendingRequest.ResolvingObject is Image)//图片的时候 缓存就不再继续下载
                     {
                         if (pendingRequest.Uri.IsAbsoluteUri)
                         {
                             //http://sj.lexun.com/phone_upload/rc_pic/zixun/490854/lx_0_490854.jpg

                            
                             //load from isolated storage if has been cached
                             if (IsImageCached(pendingRequest.Uri))
                             {
                                 if (null != LoadCachedImage(pendingRequest.Uri))
                                 {
                                     pendingCompletions.Enqueue(new PendingCompletion(pendingRequest.ResolvingObject, pendingRequest.Uri, LoadCachedImage(pendingRequest.Uri)));
                                 }
                             }
                             else
                             {
                                 StreamResourceInfo sriSystem = Application.GetResourceStream(new Uri("Icon/defaultIcon.png", UriKind.RelativeOrAbsolute));
                                 Deployment.Current.Dispatcher.BeginInvoke(() =>
                                    {
                                        var bitmapImage = new BitmapImage();
                                        bitmapImage.CreateOptions = BitmapCreateOptions.BackgroundCreation;
                                      //StreamResourceInfo sriSystem = Application.GetResourceStream(new Uri("Icon/defaultIcon.png", UriKind.RelativeOrAbsolute));
                                        bitmapImage.SetSource(sriSystem.Stream);
                                        //bitmap = bitmapImage;
                                        ((Image)pendingRequest.ResolvingObject).Source  = bitmapImage;                                     
                                        //((Image)pendingRequest.ResolvingObject).Stretch = Stretch.Uniform;  //填充方式
                                        // bitmap;
                                        sriSystem.Stream.Dispose();
                                        WaitUiThread.Set();
                                    });
                                 WaitUiThread.WaitOne();
                                 if (isNonPictureMode==false)
                                 {
                                     var webRequest = HttpWebRequest.CreateHttp(pendingRequest.Uri);
                                     webRequest.AllowReadStreamBuffering = true; // Don't want to block this thread or the UI thread on network access
                                     webRequest.BeginGetResponse(HandleGetResponseResult, new ResponseState(webRequest, pendingRequest.ResolvingObject, pendingRequest.Uri));
                                 }
                                 Thread.Sleep(1);
                             }
                         }
                         else
                         {
                             var originalUriString = pendingRequest.Uri.OriginalString;
                             // Trim leading '/' to avoid problems
                             var resourceStreamUri = originalUriString.StartsWith("/", StringComparison.Ordinal) ? new Uri(originalUriString.TrimStart('/'), UriKind.Relative) : pendingRequest.Uri;
                             // Enqueue resource stream for completion
                             var streamResourceInfo = Application.GetResourceStream(resourceStreamUri);
                             if (null != streamResourceInfo)
                             {
                                 pendingCompletions.Enqueue(new PendingCompletion(pendingRequest.ResolvingObject, pendingRequest.Uri, streamResourceInfo.Stream));
                             }
                         }
                     }
                     else//这个时候是xml
                     {
                         if (pendingRequest.Uri.IsAbsoluteUri)
                         {
                             //load from isolated storage if has been cached
                             if (IsImageCached(pendingRequest.Uri))
                             {
                                 if (null != LoadCachedImage(pendingRequest.Uri))
                                 {
                                     pendingCompletions.Enqueue(new PendingCompletion(pendingRequest.ResolvingObject, pendingRequest.Uri, LoadCachedImage(pendingRequest.Uri)));
                                 }
                             }
                            
                             var webRequest = HttpWebRequest.CreateHttp(pendingRequest.Uri);
                             webRequest.AllowReadStreamBuffering = true; // Don't want to block this thread or the UI thread on network access
                             webRequest.Method = "POST";
                             webRequest.Headers["Pragma"] = "no-cache"; //禁用缓存
                             webRequest.Headers["Cache-Control"] = "no-cache"; //禁用缓存    
                             //
                             webRequest.BeginGetResponse(HandleGetResponseResult, new ResponseState(webRequest, pendingRequest.ResolvingObject, pendingRequest.Uri));

                         }
                     }
                    Thread.Sleep(1);
                }
                for (var i = 0; (i < pendingResponses.Count) && (i < WorkItemQuantum); i++)
                {
                    var pendingResponse = pendingResponses.Dequeue();
                    var responseState = (ResponseState)pendingResponse.AsyncState;

                    try
                    {
                     
                        var response = responseState.WebRequest.EndGetResponse(pendingResponse);
                        pendingCompletions.Enqueue(new PendingCompletion(responseState.ResolvingObject, responseState.Uri, response.GetResponseStream()));
                    }
                    catch (WebException)
                    {
                       #region  异常处理的代码
                        // Ignore web exceptions (ex: not found)
                        if (responseState.ResolvingObject is PhoneInfoCenterView)
                        {
                            var phoneinof = (PhoneInfoCenterView)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                phoneinof.Result = -1;
                                WaitUiThread.Set();
                               // MessageBox.Show("网络错误,请稍后重试");
                            });
                            WaitUiThread.WaitOne();
                        }
                        else if (responseState.ResolvingObject is PhoneInfoContentView)
                        {
                            var phoneinof = (PhoneInfoContentView)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {

                                phoneinof.Result = -1;
                                phoneinof.ResultMsg = "网络错误！";
                               // phoneinof.
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                        }
                        else if (responseState.ResolvingObject is ShrewdEyeView)
                        {

                            var phoneinof = (ShrewdEyeView)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                //phoneinof.ImageVis = true;
                                phoneinof.IsLoadSuccess = -1;
                               // phoneinof.prg.Visibility = Visibility.Collapsed;
                                MessageBox.Show("网络错误,请稍后重试");
                            });
                        }
                        else if (responseState.ResolvingObject is SearchResultView)
                        {
                            var phoneinof = (SearchResultView)responseState.ResolvingObject;
                               Deployment.Current.Dispatcher.BeginInvoke(() =>
                               {
                                   phoneinof.Result = -1;
                                   phoneinof.Message = "网络错误，获取不到你需要的内容";
                                   WaitUiThread.Set();
                               });
                               WaitUiThread.WaitOne();
                              
                            
                        }
                        else if (responseState.ResolvingObject is Image)
                        {
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                               // ImageSource bitmap;
                                var bitmapImage = new BitmapImage();
                                bitmapImage.CreateOptions = BitmapCreateOptions.BackgroundCreation;
                                StreamResourceInfo sriSystem = Application.GetResourceStream(new Uri("Icon/defaultIcon.png", UriKind.RelativeOrAbsolute));
                                bitmapImage.SetSource(sriSystem.Stream);
                              //  bitmap = bitmapImage;
                                ((Image)responseState.ResolvingObject).Stretch = Stretch.Uniform;
                                ((Image)responseState.ResolvingObject).Source = bitmapImage;
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                        }
                        else if (responseState.ResolvingObject is phonePkView)
                        {//
                            var phoneinof = (phonePkView)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                phoneinof.ImageVis = true;
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                          
                            MessageBox.Show("网络错误,请稍后重试");
                        }
                        else if (responseState.ResolvingObject is TypeParameter)
                        {
                            var phoneinof = (TypeParameter)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                phoneinof.ImageVis = true;
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                          
                            MessageBox.Show("网络错误,请稍后重试");
                        }
                        else if (responseState.ResolvingObject is TypePrice)
                        {
                            var phoneinof = (TypePrice)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                phoneinof.Result= - 1;
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                           // MessageBox.Show("网络错误,请稍后重试");
                        }
                        else if (responseState.ResolvingObject is TypePicture)
                        {
                            var phoneinof = (TypePicture)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                phoneinof.Result = -1;
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                        }
                        else if (responseState.ResolvingObject is TypeCommentView)
                        {
                            var phoneinof = (TypeCommentView)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                phoneinof.Result = -1;
                                MessageBox.Show("网络错误,请稍后重试");
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                        }
                        else if (responseState.ResolvingObject is ReplyResult)
                        {
                            var phoneinof = (ReplyResult)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                phoneinof.Result = -1;
                                phoneinof.ResultMsg = "网络错误，没有取到相应数据";
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                           
                           
                           // MessageBox.Show("网络错误,请稍后重试");
                        }
                        else if (responseState.ResolvingObject is BibleView)
                        {
                            var phoneinof = (BibleView)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                phoneinof.Result = -1;
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                          
                        }
                        else if (responseState.ResolvingObject is PhonePkDetail)
                        {
                            var phoneinof = (PhonePkDetail)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                phoneinof.IsShowError = true;
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                           
                        }
                        else if (responseState.ResolvingObject is TypeArea)
                        {
                            var phoneinof = (TypeArea)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                phoneinof.Result = -1;
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                           
                            
                        }
                        else if (responseState.ResolvingObject is RegisteAccount)
                        {
                            var phoneinof = (RegisteAccount)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                phoneinof.Result = -1;
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                            
                            //放了-1之后那边的网络处理自然处置
                        }
                        else if (responseState.ResolvingObject is ShowDownloadView)
                        {
                            var phoneinof = (ShowDownloadView)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                phoneinof.Result = -1;
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                           
                            //放了-1之后那边的网络处理自然处置
                        }//ConversationObject
                        else if (responseState.ResolvingObject is ConversationObject)
                        {
                            var phoneinof = (ConversationObject)responseState.ResolvingObject;
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                phoneinof.Result = -1;
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                        }//
                        #endregion
                    }
                    Thread.Sleep(1);
                }
                // Process pending completions
                if (0 < pendingCompletions.Count)
                {
                    
                    // Get the Dispatcher and process everything that needs to happen on the UI thread in one batch
                    while (0 < pendingCompletions.Count)
                    {
                        progressPending = pendingCompletions.Dequeue();
                        if (progressPending.list.Count>0)
                        {
                            progressPending.list.Clear();
                        }
                        ParseXml();
                    }
                }
            }
        }
        public static string GetParsePath(string url)
        {
            return url.Replace("://", "").Replace("/","_");
        }
        private static bool IsImageCached( Uri u)
        {
            //对字符串机型MD5加密，防止超过180，引起文件名字过长的异常 
            string tempUmd=MD5.GetMd5String(GetParsePath(u.ToString()));
            string filePath = System.IO.Path.Combine("Xmls", tempUmd);         
           // Debug.WriteLine(filePath.Length);
            using (var store=IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (store.FileExists(filePath))
                {
                    return true;
                }
            }
            return false;
        }
        public static Stream LoadCachedImage(Uri u)
        {
            string tempUmd = MD5.GetMd5String(GetParsePath(u.ToString()));

            string filePath = System.IO.Path.Combine("Xmls", tempUmd);
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!store.FileExists(filePath))
                {
                  //  return null;
                    StreamResourceInfo sriSystem = Application.GetResourceStream(new Uri("Icon/defaultIcon.png", UriKind.RelativeOrAbsolute));

                    return sriSystem.Stream;
                }
                return store.OpenFile(filePath, FileMode.Open, FileAccess.Read);
            }
        }
        private static bool CacheImage(Stream source,Uri u)
        {
            if (source.Length==0)
            {
                return false;
            }
            string tempUmd = MD5.GetMd5String(GetParsePath(u.ToString()));

            string filePath = System.IO.Path.Combine("Xmls", tempUmd);
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                try
                {
                    if (!store.DirectoryExists("Xmls"))
                    {
                        store.CreateDirectory("Xmls");
                    }
                    using (var stream = store.OpenFile(filePath, FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        byte[] bytes = new byte[source.Length];
                        source.Read(bytes, 0, (int)source.Length);
                        stream.Write(bytes, 0, (int)source.Length);
                    }
                    return true;
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                    return false;
                    throw;
                }
            }
        }
        private static void OnUriSourceChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            var resolving = (DependencyObject)o;
            var uri = (Uri)e.NewValue;

            //if (!IsEnabled || DesignerProperties.IsInDesignTool)
            //{
            //    // Avoid handing off to the worker thread (can cause problems for design tools)
            //    image.Source = new BitmapImage(uri);
            //}
            //else
            //{
                lock (_syncBlock)
                {
                    // Enqueue the request
                    _pendingRequests.Enqueue(new PendingRequest(resolving, uri));
                    Monitor.Pulse(_syncBlock);
                }
            //}
        }
        private static void HandleGetResponseResult(IAsyncResult result)
        {
            lock (_syncBlock)
            {
                // Enqueue the response
                _pendingResponses.Enqueue(result);
                Monitor.Pulse(_syncBlock);
            }
        }
        private class PendingRequest
        {
            public DependencyObject ResolvingObject { get; private set; }
            public Uri Uri { get; private set; }
            public PendingRequest(DependencyObject resolving, Uri uri)
            {
                ResolvingObject = resolving;
                Uri = uri;
            }
        }
        private class ResponseState
        {
            public WebRequest WebRequest { get; private set; }
            public DependencyObject ResolvingObject { get; private set; }
            public Uri Uri { get; private set; }
            public ResponseState(WebRequest webRequest, DependencyObject resolving, Uri uri)
            {
                WebRequest = webRequest;
                ResolvingObject = resolving;
                Uri = uri;
            }
        }
        public class PendingCompletion
        {
            public DependencyObject ResolvingObject { get; private set; }
            public List<object> list;
            public Uri Uri { get; private set; }
            public Stream Stream { get; private set; }
            public PendingCompletion(DependencyObject resolving, Uri uri, Stream stream)
            {
                ResolvingObject=resolving;
                Uri = uri;
                Stream = stream;
                list = new List<object>();
            }
            
        }
        //加载成功返回>=0
        //加载失败<0
        //加载资讯的主页面
        private static void LoadFirstPhoneInfoCenterPage()
        {
            try
            {
                XDocument xdoc=null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch(Exception)
                {

                }
                if (xdoc==null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }

                var PhoneInfoCenter = progressPending.ResolvingObject as PhoneInfoCenterView;
                if (PhoneInfoCenter == null)
                {
                    return;
                }
                foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
                {
                    int result = int.Parse(element.Attribute("result").Value);
                    string resultmsg = element.Attribute("resultmsg").Value;
                    int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                    if (0 == result)
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            PhoneInfoCenter.Result = 1;
                            WaitUiThread.Set();
                        });
                        WaitUiThread.WaitOne();
                        progressPending.Stream.Dispose();
                        progressPending = null;
                        return;
                    }
                }
                foreach (XElement element in xdoc.Element("lexun").Descendants("page"))
                {
                    PhoneInfoCenter.TotalPage = int.Parse(element.Attribute("total").Value);
                    PhoneInfoCenter.CurrentPage = int.Parse(element.Attribute("p").Value);
                }

                if (PhoneInfoCenter.CurrentPage == 1)
                {
                    progressPending.Stream.Seek(0, SeekOrigin.Begin);
                    CacheImage(progressPending.Stream, progressPending.Uri);
                }
                if (PhoneInfoCenter.TotalPage <= 0)//安全检查
                    return;

                    foreach (XElement element in xdoc.Element("lexun").Descendants("topic"))
                    {
                      PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                        //属性
                        infoItem.Topicid = element.Attribute("topicid").Value;
                        infoItem.Userid = element.Attribute("userid").Value;
                        infoItem.Ztid = element.Attribute("ztid").Value;
                        infoItem.Readcount = element.Attribute("readcount").Value;
                        infoItem.Replycount = element.Attribute("rlycount").Value;
                        //节点
                        infoItem.Title = element.Element("title").Value;
                        infoItem.Keywords = element.Element("keywords").Value;
                        infoItem.Writetime = element.Element("writetime").Value;
                        infoItem.Replytime = element.Element("replytime").Value;
                        infoItem.Picurl = element.Element("picurl").Value;
                        try
                        {
                            infoItem.Content = element.Element("content").Value;
                        }
                        catch(Exception e)
                        {
                            Debug.WriteLine(e.Message);
                            
                        }

                        
                        if (infoItem.Content != null)
                        {
                            if (infoItem.Content == "...")
                            {
                                infoItem.Type = "Head";
                            }
                            else
                            {
                                infoItem.Type = "Main";
                            }
                        }
                        else
                        {
                            infoItem.Type = "Main";
                        }
                        infoItem.IsTaped = false;
                        progressPending.list.Add(infoItem);
                    }
                    if (PhoneInfoCenter.PoneInfoCenterItems.Count > 0)
                    {
                        if (PhoneInfoCenter.CurrentPage * PhoneInfoCenter.PageSize < PhoneInfoCenter.TotalPage)
                        {
                            PhoneInfoCenterItem infoItem1 = new PhoneInfoCenterItem();
                            infoItem1.Title = "加载更多...";
                            infoItem1.Type = "Tail";
                            progressPending.list.Add(infoItem1);
                        }
                    }
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        if (PhoneInfoCenter.PoneInfoCenterItems.Count == 0)
                        {
                            for (int i = 0; i < progressPending.list.Count; i++)
                            {
                                PhoneInfoCenter.PoneInfoCenterItems.Add((PhoneInfoCenterItem)progressPending.list[i]);
                            }

                        }
                        else
                        {
                            int position = 0;
                            PhoneInfoCenter.PoneInfoCenterItems.RemoveAt(PhoneInfoCenter.PoneInfoCenterItems.Count - 1);
                            for (int i = 0; i < progressPending.list.Count; i++, position++)
                            {
                                if (PhoneInfoCenter.PoneInfoCenterItems.Count > position)
                                {
                                    if (PhoneInfoCenter.PoneInfoCenterItems[position].Title != ((PhoneInfoCenterItem)progressPending.list[position]).Title ||
                                        PhoneInfoCenter.PoneInfoCenterItems[position].Picurl != ((PhoneInfoCenterItem)progressPending.list[position]).Picurl)
                                    {
                                        PhoneInfoCenter.PoneInfoCenterItems[position] = (PhoneInfoCenterItem)progressPending.list[position];
                                    }
                                }
                                else
                                {
                                    PhoneInfoCenter.PoneInfoCenterItems.Add((PhoneInfoCenterItem)progressPending.list[position]);
                                }

                            }
                            if (position < PhoneInfoCenter.PoneInfoCenterItems.Count)
                            {
                                for (int i = position; i < PhoneInfoCenter.PoneInfoCenterItems.Count; )
                                {
                                    PhoneInfoCenter.PoneInfoCenterItems.RemoveAt(i);
                                }
                            }
                        }
                        progressPending.Stream.Dispose();
                        progressPending = null;

                        PhoneInfoCenter.Result = 2;
                        WaitUiThread.Set();
                    });
                    WaitUiThread.WaitOne();
                //}
               
            }
            catch(Exception e)
            {
                Debug.WriteLine(e.Message);
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        private static void AddPhoneInfoCenterPage()
        {
            try
            {
            #region
                //XDocument xdoc = XDocument.Load(pendingCompletion.Stream);
                //if (pendingCompletion.ResolvingObject is PhoneInfoCenterView)
                //{//如果是首页
                //    var PhoneInfoCenter = pendingCompletion.ResolvingObject as PhoneInfoCenterView;
                    
                //    //PhoneInfoCenter.prg.Visibility = Visibility.Collapsed;
                //    foreach (XElement element in xdoc.Descendants("resultinfo"))
                //    {
                //        //如果有错弹出错误处理;
                //        int result = int.Parse(element.Attribute("result").Value);
                //        string resultmsg = element.Attribute("resultmsg").Value;
                //        int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                //        if (0 == result)
                //        {
                //            PhoneInfoCenter.Result = 1;
                //            return ;
                //        }

                //    }

                   
                //    if (PhoneInfoCenter.CurrentPage <= 0)
                //        return ;
                //    if (PhoneInfoCenter.PoneInfoCenterItems.Count == 0)
                //    {
                //        //前面没有项目，说明条用此函数追加有错误
                //        return ;
                //       //用pos下表相同的元素就不会重复刷新
                //    }
                //    PhoneInfoCenter.PoneInfoCenterItems.RemoveAt(PhoneInfoCenter.PoneInfoCenterItems.Count-1);
                //        //删除上面“更多”的设置

                //    foreach (XElement element in xdoc.Element("lexun").Descendants("topic"))
                //        {
                //            PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                //            XmlReader xtr = element.CreateReader();
                //            string currentElement = null;
                //            while (xtr.Read())
                //            {
                //                //Debug.WriteLine("NodeType is {0},{1},{2}", xtr.NodeType, xtr.LocalName, xtr.Value);
                //                switch (xtr.NodeType)
                //                {
                //                    case XmlNodeType.Element:
                //                        currentElement = xtr.LocalName;
                //                        if (xtr.LocalName == "topic")
                //                        {
                //                            //
                //                            while (xtr.MoveToNextAttribute())
                //                            {
                //                                switch (xtr.Name)
                //                                {
                //                                    case "topicid":
                //                                        infoItem.Topicid = xtr.Value;
                //                                        break;
                //                                    case "userid":
                //                                        infoItem.Userid = xtr.Value;
                //                                        break;
                //                                    case "ztid":
                //                                        infoItem.Ztid = xtr.Value;
                //                                        break;
                //                                    case "readcount":
                //                                        infoItem.Readcount = xtr.Value;
                //                                        break;
                //                                    case "rlycount":
                //                                        infoItem.Replycount = xtr.Value;
                //                                        break;

                //                                }
                //                            }
                //                        }
                //                        break;
                //                    case XmlNodeType.CDATA:
                //                    case XmlNodeType.Text:
                //                        switch (currentElement)
                //                        {
                //                            case "title":
                //                                infoItem.Title = xtr.Value;
                //                                break;
                //                            case "keywords":
                //                                infoItem.Keywords = xtr.Value;
                //                                break;
                //                            case "writetime":
                //                                infoItem.Writetime = xtr.Value;
                //                                break;
                //                            case "replytime":
                //                                infoItem.Replytime = xtr.Value;
                //                                break;
                //                            case "picurl":
                //                                infoItem.Picurl = xtr.Value;
                //                                break;
                //                            case "content":
                //                                 infoItem.Content = xtr.Value;
                //                                break;

                //                        }
                //                        break;
                //                    default:
                //                        break;
                //                }


                //            }
                //            if (infoItem.Content != null)
                //            {
                //                if (infoItem.Content == "...")
                //                {
                //                    infoItem.Type = "Head";
                //                }
                //                else
                //                {
                //                    infoItem.Type = "Main";
                //                }
                //            }
                //            else
                //            {
                //                infoItem.Type = "Main";
                //            }
                //            PhoneInfoCenter.PoneInfoCenterItems.Add(infoItem);
                //            //用pos下表相同的元素就不会重复刷新
                //        }
                //    if (PhoneInfoCenter.CurrentPage * PhoneInfoCenter .PageSize< PhoneInfoCenter.TotalPage)
                //        {
                //                PhoneInfoCenterItem tailinfoItem = new PhoneInfoCenterItem();
                //            tailinfoItem.Title = "更多";
                //            tailinfoItem.Keywords = null;
                //            tailinfoItem.Writetime = null;
                //            tailinfoItem.Replytime = null;
                //            tailinfoItem.Picurl = null;
                //            tailinfoItem.Content = null;
                //            tailinfoItem.Type = "Tail";
                //            PhoneInfoCenter.PoneInfoCenterItems.Add(tailinfoItem);
                //        }
                //        //PhoneInfoCenter.prg.Visibility = Visibility.Collapsed;
                //      foreach (XElement element in xdoc.Element("lexun").Descendants("page"))
                //      {
                //            PhoneInfoCenter.CurrentPage = int.Parse(element.Attribute("p").Value);
                //      }
                //      PhoneInfoCenter.Result=2;
                //    }
                //    //应该找到页面的说明，查看是否有下一个页面确定是否添加tail项目
              
               
            //这里可以增加其他类型的判断
                #endregion
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                {

                }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }

                var PhoneInfoCenter = progressPending.ResolvingObject as PhoneInfoCenterView;
                if (PhoneInfoCenter == null)
                {
                    return;
                }
                foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
                {
                    int result = int.Parse(element.Attribute("result").Value);
                    string resultmsg = element.Attribute("resultmsg").Value;
                    int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                    if (0 == result)
                    {
                        PhoneInfoCenter.Result = 1;
                        return;
                    }
                }
                foreach (XElement element in xdoc.Element("lexun").Descendants("page"))
                {
                    PhoneInfoCenter.TotalPage = int.Parse(element.Attribute("total").Value);
                    PhoneInfoCenter.CurrentPage = int.Parse(element.Attribute("p").Value);
                }

                if (PhoneInfoCenter.CurrentPage == 1)
                {
                    progressPending.Stream.Seek(0, SeekOrigin.Begin);
                    CacheImage(progressPending.Stream, progressPending.Uri);
                }
                if (PhoneInfoCenter.TotalPage <= 0)//安全检查
                    return;
              
                foreach (XElement element in xdoc.Element("lexun").Descendants("topic"))
                {
                    PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                    //属性
                    infoItem.Topicid = element.Attribute("topicid").Value;
                    infoItem.Userid = element.Attribute("userid").Value;
                    infoItem.Ztid = element.Attribute("ztid").Value;
                    infoItem.Readcount = element.Attribute("readcount").Value;
                    infoItem.Replycount = element.Attribute("rlycount").Value;
                    //节点
                    infoItem.Title = element.Element("title").Value;
                    infoItem.Keywords = element.Element("keywords").Value;
                    infoItem.Writetime = element.Element("writetime").Value;
                    infoItem.Replytime = element.Element("replytime").Value;
                    infoItem.Picurl = element.Element("picurl").Value;
                    try
                    {
                        infoItem.Content = element.Element("content").Value;
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.Message);

                    }
                    if (infoItem.Content != null)
                    {
                        if (infoItem.Content == "...")
                        {
                            infoItem.Type = "Head";
                        }
                        else
                        {
                            infoItem.Type = "Main";
                        }
                    }
                    else
                    {
                        infoItem.Type = "Main";
                    }
                    infoItem.IsTaped = false;
                    progressPending.list.Add(infoItem);
                }
               if (PhoneInfoCenter.CurrentPage * PhoneInfoCenter.PageSize < PhoneInfoCenter.TotalPage)
                    {
                        PhoneInfoCenterItem infoItem1 = new PhoneInfoCenterItem();
                        infoItem1.Title = "加载更多...";
                        infoItem1.Type = "Tail";
                        progressPending.list.Add(infoItem1);
                    }
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    PhoneInfoCenter.PoneInfoCenterItems.RemoveAt(PhoneInfoCenter.PoneInfoCenterItems.Count - 1);
                    
                        for (int i = 0; i < progressPending.list.Count; i++)
                        {
                            PhoneInfoCenter.PoneInfoCenterItems.Add((PhoneInfoCenterItem)progressPending.list[i]);
                        }
                   
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    PhoneInfoCenter.Result = 2;
                    WaitUiThread.Set();
                });
                WaitUiThread.WaitOne();
            }
            catch (Exception e)
            {
               Debug.WriteLine(e.Message);
               progressPending.Stream.Dispose();
               progressPending = null;
              
            }
            
        }
        //加载成功返回>=0
        //加载失败<0
        //加载手机资讯页面的更多的项目
        //加载更多的页面
        private static void LoadFirstPhoneInfoMorePage()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                {

                }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }

                if (progressPending.ResolvingObject is PhoneInfoCenterView)
                {
                    progressPending.Stream.Seek(0, SeekOrigin.Begin);
                    CacheImage(progressPending.Stream, progressPending.Uri);
                    var PhoneInfoCenter = progressPending.ResolvingObject as PhoneInfoCenterView;
                    foreach (XElement element in xdoc.Element("lexun").Descendants("topic"))
                    {
                       
                        int result = int.Parse(element.Attribute("result").Value);
                        string resultmsg = element.Attribute("resultmsg").Value;
                        int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                        if (0 == result)
                        {
                            PhoneInfoCenter.Result = 1;
                            return;
                        }

                    }
                 
                       
                        foreach (XElement element in xdoc.Element("lexun").Descendants("type"))
                        {
                            PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();

                            infoItem.Title = (string)element.Element("typename").Value;
                            infoItem.Topicid = (string)element.Attribute("menuid").Value;
                            switch (infoItem.Topicid)
                            {
                                case "2391":
                                    //android专区
                                    infoItem.Picurl = "Icon/info/m_android.png";
                                    break;
                                case "2398":
                                    //iphoen专区
                                    infoItem.Picurl = "Icon/info/m_iphone.png";
                                    break;
                                case "2265":

                                    infoItem.Picurl = "Icon/info/m_1500.png";
                                    break;
                                case "2266":
                                    infoItem.Picurl = "Icon/info/m_2500.png";
                                    break;
                                case "2267":
                                    infoItem.Picurl = "Icon/info/m_2500-3k.png";
                                    break;
                                case "2268":
                                    infoItem.Picurl = "Icon/info/m_3000.png";
                                    break;
                                //
                                case "2270":
                                    infoItem.Picurl = "Icon/info/m_gz.png";
                                    break;
                                case "2271":
                                    infoItem.Picurl = "Icon/info/m_bj.png";
                                    break;
                                case "2272":
                                    infoItem.Picurl = "Icon/info/m_sz.png";
                                    break;
                                case "2273":
                                    infoItem.Picurl = "Icon/info/m_sh.png";
                                    break;
                                case "2285":
                                    infoItem.Picurl = "Icon/info/m_htc.png";
                                    break;
                                case "2284":
                                    infoItem.Picurl = "Icon/info/m_symbian.png";
                                    break;
                                case "2286":
                                    infoItem.Picurl = "Icon/info/m_moto.png";
                                    break;
                                case "2287":
                                    infoItem.Picurl = "Icon/info/m_se.png";
                                    break;
                                case "2288":
                                    infoItem.Picurl = "Icon/info/m_gc.png";
                                    break;
                                case "2289":
                                    infoItem.Picurl = "Icon/info/m_htc.png";
                                    break;
                              
                                default:
                                    infoItem.Picurl = "Icon/info/m_sg2.png";
                                    break;

                            }
                            progressPending.list.Add(infoItem);
                        }
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            if (PhoneInfoCenter.PoneInfoCenterItems.Count == 0)
                            {
                                for (int i = 0; i < progressPending.list.Count; i++)
                                {
                                    PhoneInfoCenter.PoneInfoCenterItems.Add((PhoneInfoCenterItem)progressPending.list[i]);
                                }

                            }
                            else
                            {
                                int position = 0;
                                PhoneInfoCenter.PoneInfoCenterItems.RemoveAt(PhoneInfoCenter.PoneInfoCenterItems.Count - 1);
                                for (int i = 0; i < progressPending.list.Count; i++, position++)
                                {
                                    if (PhoneInfoCenter.PoneInfoCenterItems.Count > position)
                                    {
                                        if (PhoneInfoCenter.PoneInfoCenterItems[position].Title != ((PhoneInfoCenterItem)progressPending.list[position]).Title ||
                                            PhoneInfoCenter.PoneInfoCenterItems[position].Picurl != ((PhoneInfoCenterItem)progressPending.list[position]).Picurl)
                                        {
                                            PhoneInfoCenter.PoneInfoCenterItems[position] = (PhoneInfoCenterItem)progressPending.list[position];
                                        }
                                    }
                                    else
                                    {
                                        PhoneInfoCenter.PoneInfoCenterItems.Add((PhoneInfoCenterItem)progressPending.list[position]);
                                    }

                                }
                                if (position < PhoneInfoCenter.PoneInfoCenterItems.Count)
                                {
                                    for (int i = position; i < PhoneInfoCenter.PoneInfoCenterItems.Count; )
                                    {
                                        PhoneInfoCenter.PoneInfoCenterItems.RemoveAt(i);
                                    }
                                }
                            }
                            progressPending.Stream.Dispose();
                            progressPending = null;

                            PhoneInfoCenter.Result = 2;
                            WaitUiThread.Set();
                        });
                        WaitUiThread.WaitOne();
                    //else
                    //{
                    //    foreach (XElement element in xdoc.Element("lexun").Descendants("type"))
                    //    {
                    //        PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                    //        infoItem.Title = (string)element.Element("typename").Value;
                    //        infoItem.Topicid = (string)element.Attribute("menuid").Value;
                    //        switch (infoItem.Topicid)
                    //        {
                    //            case "2391":
                    //                infoItem.Picurl = "Icon/info/m_android.png";
                    //                break;
                    //            case "2398":
                                    
                    //                infoItem.Picurl = "Icon/info/m_iphone.png";
                    //                break;
                    //            case "2265":
                    //                infoItem.Picurl = "Icon/info/m_1500.png";
                    //                break;
                    //            case "2266":
                    //                infoItem.Picurl = "Icon/info/m_2500.png";
                    //                break;
                    //            case "2267":
                    //                infoItem.Picurl = "Icon/info/m_2500-3k.png";
                    //                break;
                    //            case "2268":
                    //                infoItem.Picurl = "Icon/info/m_3000.png";
                    //                break;
                    //            case "2270":
                    //                infoItem.Picurl = "Icon/info/m_gz.png";
                    //                break;
                    //            case "2271":
                    //                infoItem.Picurl = "Icon/info/m_bj.png";
                    //                break;
                    //            case "2272":
                    //                infoItem.Picurl = "Icon/info/m_sz.png";
                    //                break;
                    //            case "2273":
                    //                infoItem.Picurl = "Icon/info/m_sh.png";
                    //                break;
                    //            case "2285":
                    //                infoItem.Picurl = "Icon/info/m_htc.png";
                    //                break;
                    //            case "2284":
                    //                infoItem.Picurl = "Icon/info/m_symbian.png";
                    //                break;
                    //            case "2286":
                    //                infoItem.Picurl = "Icon/info/m_moto.png";
                    //                break;
                    //            case "2287":
                    //                infoItem.Picurl = "Icon/info/m_se.png";
                    //                break;
                    //            case "2288":
                    //                infoItem.Picurl = "Icon/info/m_gc.png";
                    //                break;
                    //            case "2289":
                    //                infoItem.Picurl = "Icon/info/m_htc.png";
                    //                break;
                    //            default:
                    //                infoItem.Picurl = "Icon/info/m_sg2.png";
                    //                break;

                    //        }
                    //        PhoneInfoCenter.PoneInfoCenterItems.Add(infoItem);
                    //    }
                    //}
                    //PhoneInfoCenter.Result = 2;
                }
              
              
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                progressPending.Stream.Dispose();
                progressPending = null;
            }
           
        }
        //加载内容的页面
        private static void LoadFirstPhoneContent()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                {

                }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }

                if (progressPending.ResolvingObject is PhoneInfoContentView)
                {
                    var PhoneContent = progressPending.ResolvingObject as PhoneInfoContentView;
                    //PhoneContent.prg.Visibility = Visibility.Collapsed;
                    foreach (XElement element in xdoc.Descendants("resultinfo"))
                    {
                        int result = int.Parse(element.Attribute("result").Value);
                        string resultmsg = element.Attribute("resultmsg").Value;
                        int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                        if (0 == result)
                        {
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                PhoneContent.Result = 1;
                                PhoneContent.ResultMsg = "网络错误！";
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                        
                            progressPending.Stream.Dispose();
                            progressPending = null;
                            return;
                        }
                      
                    }
                    foreach (XElement element in xdoc.Element("lexun").Descendants("page"))
                    {
                        PhoneContent.CurrentPage = int.Parse(element.Attribute("p").Value);
                        PhoneContent.TotalPage = int.Parse(element.Attribute("total").Value);
                    }
                    if (PhoneContent.CurrentPage <= 0)
                        return;
                    if (PhoneContent.CurrentPage == 1)
                    {
                        progressPending.Stream.Seek(0, SeekOrigin.Begin);
                        CacheImage(progressPending.Stream, progressPending.Uri);
                    }
                    foreach (XElement element in xdoc.Element("lexun").Descendants("topic"))
                    {
                        PhoneContent.ReadCount = element.Attribute("readcount").Value;
                        PhoneContent.ReplyCount = element.Attribute("rlycount").Value;
                        PhoneContent.Title = element.Element("title").Value;
                        PhoneContent.Writetime = element.Element("writetime").Value;
                        PhoneContent.Replytime = element.Element("replytime").Value;
                       
                    }
                   
                    //if (PhoneContent.PoneConterItems.Count==0)
                    //{
                        foreach (XElement element in xdoc.Element("lexun").Descendants("contentinfo"))
                        {
                            foreach (XElement elementChild in element.Descendants("content"))
                            {
                                PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                                infoItem.Content = elementChild.Value;
                                infoItem.Type = "Main";
                                progressPending.list.Add(infoItem);
                               // PhoneContent.PoneConterItems.Add(infoItem);
                            }
                            foreach (XElement elementChild in element.Descendants("file"))
                            {
                                PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                                infoItem.Picurl = elementChild.Element("fileprevurl").Value;
                                infoItem.Keywords = elementChild.Element("fileacturl").Value;
                                infoItem.Type = "Head";
                                progressPending.list.Add(infoItem);
                               // PhoneContent.PoneConterItems.Add(infoItem);
                            }
                          
                        }
                        bool allowAddAdvert = true;
                        foreach (XElement element in xdoc.Element("lexun").Descendants("adinfo"))
                        {
                            if (allowAddAdvert == true)
                            {
                                allowAddAdvert = false;
                                PhoneInfoCenterItem HotTitle = new PhoneInfoCenterItem();
                                HotTitle.Content = "商家信息";
                                HotTitle.Type = "Title";
                                progressPending.list.Add(HotTitle);
                                //PhoneContent.PoneConterItems.Add(HotTitle);
                            }
                            try
                            {
                                PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                                XmlReader xtr = element.CreateReader();
                                string currentElement = null;
                                while (xtr.Read())
                                {
                                    //Debug.WriteLine("NodeType is {0},{1},{2}", xtr.NodeType, xtr.LocalName, xtr.Value);
                                    switch (xtr.NodeType)
                                    {
                                        case XmlNodeType.Element:
                                            currentElement = xtr.LocalName;
                                            break;
                                        case XmlNodeType.CDATA:
                                        case XmlNodeType.Text:
                                            switch (currentElement)
                                            {
                                                case "name":
                                                    infoItem.Title = xtr.Value;
                                                    break;
                                                case "url":
                                                    infoItem.Topicid = xtr.Value;
                                                    infoItem.Type = "Tail";
                                                    progressPending.list.Add(infoItem);
                                                    //PhoneContent.PoneConterItems.Add(infoItem);
                                                    infoItem = new PhoneInfoCenterItem();
                                                    break;
                                            }//switch end
                                            break;
                                    }//switch end
                                }//while end

                            }
                            catch (Exception)
                            {

                            }
                        }
                    
                        bool allowAddNew = true;
                        foreach (XElement element in xdoc.Element("lexun").Descendants("topicnew"))
                        {
                            if (allowAddNew==true)
                            {
                                allowAddNew = false;
                                PhoneInfoCenterItem NewTitle = new PhoneInfoCenterItem();
                                NewTitle.Content = "最新资讯";
                                NewTitle.Type = "Title";
                                progressPending.list.Add(NewTitle);
                                //PhoneContent.PoneConterItems.Add(NewTitle);
                            }
                            XmlReader xtr = element.CreateReader();
                            string currentElement = null;
                            PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                            while (xtr.Read())
                            {     
                                //Debug.WriteLine("NodeType is {0},{1},{2}", xtr.NodeType, xtr.LocalName, xtr.Value);
                                switch (xtr.NodeType)
                                {
                                    case XmlNodeType.Element:
                                        currentElement = xtr.LocalName;
                                        if (currentElement == "topic")
                                        {//
                                            while (xtr.MoveToNextAttribute())
                                            {
                                                switch (xtr.Name)
                                                {
                                                    case "readcount":
                                                        PhoneContent.ReadCount = xtr.Value;
                                                        break;
                                                    case "rlycount":
                                                        PhoneContent.ReplyCount = xtr.Value;
                                                        break;
                                                }
                                            }
                                        }
                                        break;
                                    case XmlNodeType.CDATA:
                                    case XmlNodeType.Text:

                                        switch (currentElement)
                                        {
                                            case "title":
                                              
                                                infoItem.Title = xtr.Value;
                                                infoItem.Type = "Tail";
                                               
                                                break;
                                            case "topicid":
                                                infoItem.Topicid = xtr.Value;
                                                break;
                                        }//switch end
                                        break;
                                   }//switch end
                              }//while end
                            progressPending.list.Add(infoItem);
                            //PhoneContent.PoneConterItems.Add(infoItem);
                        }//foreach end
                      
                        bool allowAddHot = true;
                        foreach (XElement element in xdoc.Element("lexun").Descendants("topichot"))
                        {
                            if (allowAddHot==true)
                            {
                                allowAddHot = false;
                                PhoneInfoCenterItem HotTitle = new PhoneInfoCenterItem();
                                HotTitle.Content = "热点推荐";
                                HotTitle.Type = "Title";
                                progressPending.list.Add(HotTitle);
                               //PhoneContent.PoneConterItems.Add(HotTitle);

                            }
                            PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                            XmlReader xtr = element.CreateReader();
                            string currentElement = null;
                            while (xtr.Read())
                            {
                                //Debug.WriteLine("NodeType is {0},{1},{2}", xtr.NodeType, xtr.LocalName, xtr.Value);
                                switch (xtr.NodeType)
                                {
                                    case XmlNodeType.Element:
                                        currentElement = xtr.LocalName;
                                        break;
                                    case XmlNodeType.CDATA:
                                    case XmlNodeType.Text:

                                        switch (currentElement)
                                        {
                                            case "title":
                                                infoItem.Title = xtr.Value;
                                                break;
                                            case "topicid":
                                                infoItem.Topicid = xtr.Value;
                                                break;
                                        }//switch end
                                        break;
                                }//switch end
                            }//while end
                            infoItem.Type = "Tail";
                            progressPending.list.Add(infoItem);
                            //PhoneContent.PoneConterItems.Add(infoItem);
                        }//foreach end
                        if (PhoneContent.PoneConterItems.Count > 0)
                        {
                            if (PhoneContent.CurrentPage * PhoneContent.PageSize < PhoneContent.TotalPage)
                            {
                                PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                                infoItem.Title = "加载更多...";
                                infoItem.Type = "LastTitle";
                                progressPending.list.Add(infoItem);
                                //PhoneContent.PoneConterItems.Add(infoItem);
                            }
                        }
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            if (PhoneContent.PoneConterItems.Count == 0)
                            {
                                for (int i = 0; i < progressPending.list.Count; i++)
                                {
                                    PhoneContent.PoneConterItems.Add((PhoneInfoCenterItem)progressPending.list[i]);
                                }
                            }
                            else
                            {
                                int position = 0;
                                PhoneContent.PoneConterItems.RemoveAt(PhoneContent.PoneConterItems.Count - 1);
                                for (int i = 0; i < progressPending.list.Count; i++, position++)
                                {
                                    if (PhoneContent.PoneConterItems.Count > position)
                                    {
                                        if (PhoneContent.PoneConterItems[position].Title != ((PhoneInfoCenterItem)progressPending.list[position]).Title ||
                                            PhoneContent.PoneConterItems[position].Picurl != ((PhoneInfoCenterItem)progressPending.list[position]).Picurl)
                                        {
                                            PhoneContent.PoneConterItems[position] = (PhoneInfoCenterItem)progressPending.list[position];
                                        }
                                    }
                                    else
                                    {
                                        PhoneContent.PoneConterItems.Add((PhoneInfoCenterItem)progressPending.list[position]);
                                    }

                                }
                                if (position < PhoneContent.PoneConterItems.Count)
                                {
                                    for (int i = position; i < PhoneContent.PoneConterItems.Count; )
                                    {
                                        PhoneContent.PoneConterItems.RemoveAt(i);
                                    }
                                }
                            }
                            progressPending.Stream.Dispose();
                            progressPending = null;
                            PhoneContent.Result = 2;
                            WaitUiThread.Set();
                        });
                        WaitUiThread.WaitOne();
                }//if end
             }//try end

            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                progressPending.Stream.Dispose();
                progressPending = null;
            }
           

        }
        private static void LoadMorePhoneContent()
        {

            try
            {
                //
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                {

                }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                if (progressPending.ResolvingObject is PhoneInfoContentView)
                {
                    var PhoneContent = progressPending.ResolvingObject as PhoneInfoContentView;
                  //  PhoneContent.prg.Visibility = Visibility.Collapsed;
                    foreach (XElement element in xdoc.Descendants("resultinfo"))
                    {
                        //如果有错弹出错误处理;
                        int result = int.Parse(element.Attribute("result").Value);
                        string resultmsg = element.Attribute("resultmsg").Value;
                        int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                        if (0 == result)
                        {
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                PhoneContent.Result = 1;
                                PhoneContent.ResultMsg = "网络错误！";
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                            progressPending.Stream.Dispose();
                            progressPending = null;

                        }
                    }
                    foreach (XElement element in xdoc.Element("lexun").Descendants("page"))
                    {
                        PhoneContent.CurrentPage = int.Parse(element.Attribute("p").Value);
                        PhoneContent.TotalPage = int.Parse(element.Attribute("total").Value);
                    }
                    if (PhoneContent.PoneConterItems.Count==0)
                    {
                        //此时并不是追加说明函数调用有误
                        return;
                    }
                    foreach (XElement element in xdoc.Element("lexun").Descendants("topic"))
                    {
                        PhoneContent.ReadCount = element.Attribute("readcount").Value;
                        PhoneContent.ReplyCount = element.Attribute("rlycount").Value;
                        PhoneContent.Title = element.Element("title").Value;
                        PhoneContent.Writetime = element.Element("writetime").Value;
                        PhoneContent.Replytime = element.Element("replytime").Value;

                    }
                   
                    foreach (XElement element in xdoc.Element("lexun").Descendants("contentinfo"))
                    {
                        foreach (XElement elementChild in element.Descendants("content"))
                        {
                            PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                            infoItem.Content = elementChild.Value;
                            infoItem.Type = "Main";
                            progressPending.list.Add(infoItem);
                            //PhoneContent.PoneConterItems.Add(infoItem);
                        }
                        foreach (XElement elementChild in element.Descendants("file"))
                        {
                            PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                            infoItem.Picurl = elementChild.Element("fileprevurl").Value;
                            infoItem.Keywords = elementChild.Element("fileacturl").Value;
                            infoItem.Type = "Head";
                            progressPending.list.Add(infoItem);
                            //PhoneContent.PoneConterItems.Add(infoItem);
                        }
                    }//foreach end.
                    bool allowAddNew = true;
                    foreach (XElement element in xdoc.Element("lexun").Descendants("topicnew"))
                    {
                        if (allowAddNew == true)
                        {
                            allowAddNew = false;
                            PhoneInfoCenterItem HotTitle = new PhoneInfoCenterItem();
                            HotTitle.Content = "最新资讯";
                            HotTitle.Type = "Title";
                            progressPending.list.Add(HotTitle);
                            //PhoneContent.PoneConterItems.Add(HotTitle);
                        }
                        XmlReader xtr = element.CreateReader();
                        string currentElement = null;
                        PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                        while (xtr.Read())
                        {
                            //Debug.WriteLine("NodeType is {0},{1},{2}", xtr.NodeType, xtr.LocalName, xtr.Value);
                            switch (xtr.NodeType)
                            {
                                case XmlNodeType.Element:
                                    currentElement = xtr.LocalName;
                                    break;
                                case XmlNodeType.CDATA:
                                case XmlNodeType.Text:
                                    switch (currentElement)
                                    {
                                        case "title":
                                            infoItem.Title = xtr.Value;
                                            break;
                                        case "topicid":
                                            infoItem.Topicid = xtr.Value;
                                            break;
                                    }//switch end
                                    break;
                            }//switch end
                        }//while end
                        infoItem.Type = "Tail";
                        progressPending.list.Add(infoItem);
                           // PhoneContent.PoneConterItems.Add(infoItem);
                        
                    }//foreach end
                    //添加热点
                    bool allowAddAdvert = true;
                    foreach (XElement element in xdoc.Element("lexun").Descendants("adinfo"))
                    {
                        if (allowAddAdvert == true)
                        {
                            allowAddAdvert = false;
                            PhoneInfoCenterItem HotTitle = new PhoneInfoCenterItem();
                            HotTitle.Content = "商家信息";
                            HotTitle.Type = "Title";
                            progressPending.list.Add(HotTitle);
                            //PhoneContent.PoneConterItems.Add(HotTitle);
                        }
                        try
                        {
                            PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                            XmlReader xtr = element.CreateReader();
                            string currentElement = null;
                            while (xtr.Read())
                            {
                                //Debug.WriteLine("NodeType is {0},{1},{2}", xtr.NodeType, xtr.LocalName, xtr.Value);
                                switch (xtr.NodeType)
                                {
                                    case XmlNodeType.Element:
                                        currentElement = xtr.LocalName;
                                        break;
                                    case XmlNodeType.CDATA:
                                    case XmlNodeType.Text:
                                        switch (currentElement)
                                        {
                                            case "name":
                                                infoItem.Title = xtr.Value;
                                                break;
                                            case "url":
                                                infoItem.Topicid = xtr.Value;
                                                infoItem.Type = "Tail";
                                              //  PhoneContent.PoneConterItems.Add(infoItem);
                                                progressPending.list.Add(infoItem);
                                                infoItem = new PhoneInfoCenterItem();
                                                break;
                                        }//switch end
                                        break;
                                }//switch end
                            }//while end
                           
                        }
                        catch(Exception)
                        {

                        }
                    }
                    
                    bool allowAddHot = true;
                    foreach (XElement element in xdoc.Element("lexun").Descendants("topichot"))
                    {
                        if (allowAddHot == true)
                        {
                            allowAddHot = false;
                            PhoneInfoCenterItem HotTitle = new PhoneInfoCenterItem();
                            HotTitle.Content = "最新资讯";
                            HotTitle.Type = "Title";
                            progressPending.list.Add(HotTitle);
                          //  PhoneContent.PoneConterItems.Add(HotTitle);

                        }

                        PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                        XmlReader xtr = element.CreateReader();
                        string currentElement = null;
                        while (xtr.Read())
                        {
                            //Debug.WriteLine("NodeType is {0},{1},{2}", xtr.NodeType, xtr.LocalName, xtr.Value);
                            switch (xtr.NodeType)
                            {
                                case XmlNodeType.Element:
                                    currentElement = xtr.LocalName;
                                    break;
                                case XmlNodeType.CDATA:
                                case XmlNodeType.Text:
                                    switch (currentElement)
                                    {
                                        case "title":
                                            infoItem.Title = xtr.Value;
                                            break;
                                        case "topicid":
                                            infoItem.Topicid = xtr.Value;
                                            break;
                                    }//switch end
                                    break;
                            }//switch end
                        }//while end
                        infoItem.Type = "Tail";
                        progressPending.list.Add(infoItem);
                            //PhoneContent.PoneConterItems.Add(infoItem);                        
                    }//foreach end                    
                    if (PhoneContent.PoneConterItems.Count > 0)
                    {
                        if (PhoneContent.CurrentPage * PhoneContent.PageSize < PhoneContent.TotalPage)
                        {
                            PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                            infoItem.Title = "加载更多...";
                            infoItem.Type = "LastTitle";
                            progressPending.list.Add(infoItem);
                          //  PhoneContent.PoneConterItems.Add(infoItem);
                        }
                    }

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        //PhoneContent.PoneConterItems.RemoveAt(PhoneContent.PoneConterItems.Count - 1);

                        for (int i = 0; i < progressPending.list.Count; i++)
                        {
                            PhoneContent.PoneConterItems.Add((PhoneInfoCenterItem)progressPending.list[i]);
                        }

                        progressPending.Stream.Dispose();
                        progressPending = null;
                        PhoneContent.Result = 2;
                        WaitUiThread.Set();
                    });
                    WaitUiThread.WaitOne();
                }
            }
            catch(Exception e)
            {
                Debug.WriteLine(e.Message);
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        //加载回复的页面
        private static void LoadFirstPhoneReply()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                {

                }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                if (progressPending.ResolvingObject is PhoneInfoContentView)
                 {
                     //
                     var PhoneContent = progressPending.ResolvingObject as PhoneInfoContentView;
                     foreach (XElement element in xdoc.Descendants("resultinfo"))
                     {
                         //如果有错弹出错误处理;
                         int result = int.Parse(element.Attribute("result").Value);
                         string resultmsg = element.Attribute("resultmsg").Value;
                         int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                         if (0 == result)
                         {
                            // MessageBox.Show(resultmsg, "提示!", MessageBoxButton.OK);
                             Deployment.Current.Dispatcher.BeginInvoke(() =>
                             {
                                 PhoneContent.Result = 1;
                                 PhoneContent.ResultMsg = resultmsg;
                                 WaitUiThread.Set();
                             });
                             WaitUiThread.WaitOne();
                             return;
                         }
                     }
                     foreach (XElement element in xdoc.Element("lexun").Descendants("page"))
                     {
                         PhoneContent.CurrentPage = int.Parse(element.Attribute("p").Value);
                         PhoneContent.TotalPage   = int.Parse(element.Attribute("total").Value);
                         PhoneContent.ReplyCount =  PhoneContent.TotalPage.ToString();
                     }
                     if (PhoneContent.PoneConterItems.Count==0)
                     {
                                 foreach (XElement element in xdoc.Element("lexun").Descendants("reply"))
                                 {
                                     PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                                     XmlReader xtr = element.CreateReader();
                                     string currentElement = null;
                                     while (xtr.Read())
                                     {
                                         switch (xtr.NodeType)
                                         {
                                             case XmlNodeType.Element:
                                                 currentElement = xtr.LocalName;
                                                 if (currentElement == "topic")
                                                 {//
                                                     while (xtr.MoveToNextAttribute())
                                                     {
                                                         switch (xtr.Name)
                                                         {
                                                             case "readcount":
                                                                 PhoneContent.ReadCount = xtr.Value;
                                                                 break;
                                                             case "rlycount":
                                                                 PhoneContent.ReplyCount = xtr.Value;
                                                                 break;
                                                         }
                                                     }
                                                 }
                                                 break;
                                             case XmlNodeType.CDATA:
                                             case XmlNodeType.Text:
                                                 switch (currentElement)
                                                 {
                                                     case "writetime":
                                                         infoItem.Keywords = xtr.Value;
                                                         break;
                                                     case "usernick":
                                                             infoItem.Title = xtr.Value;
                                                         break;
                                                     case "content":
                                                         infoItem.Content = xtr.Value;
                                                         break;
                                                     case "floor":
                                                         infoItem.Replytime = xtr.Value;
                                                         infoItem.Replytime += "楼";
                                                         break;
                                                 }
                                                 break;
                                             default:
                                                 break;
                                         }
                                     }
                                     infoItem.Type = "Main";
                                     if (infoItem.Title.Length == 0)
                                         infoItem.Title = "乐友";
                                     progressPending.list.Add(infoItem);
                                 }
                     }
                     Deployment.Current.Dispatcher.BeginInvoke(() =>
                     {
                         if (PhoneContent.PoneConterItems.Count == 0)
                         {
                             for (int i = 0; i < progressPending.list.Count; i++)
                             {
                                 PhoneContent.PoneConterItems.Add((PhoneInfoCenterItem)progressPending.list[i]);
                             }

                         }
                         else
                         {
                             int position = 0;
                             PhoneContent.PoneConterItems.RemoveAt(PhoneContent.PoneConterItems.Count - 1);
                             for (int i = 0; i < progressPending.list.Count; i++, position++)
                             {
                                 if (PhoneContent.PoneConterItems.Count > position)
                                 {
                                     if (PhoneContent.PoneConterItems[position].Title != ((PhoneInfoCenterItem)progressPending.list[position]).Title ||
                                         PhoneContent.PoneConterItems[position].Picurl != ((PhoneInfoCenterItem)progressPending.list[position]).Picurl)
                                     {
                                         PhoneContent.PoneConterItems[position] = (PhoneInfoCenterItem)progressPending.list[position];
                                     }
                                 }
                                 else
                                 {
                                     PhoneContent.PoneConterItems.Add((PhoneInfoCenterItem)progressPending.list[position]);
                                 }

                             }
                             if (position < PhoneContent.PoneConterItems.Count)
                             {
                                 for (int i = position; i < PhoneContent.PoneConterItems.Count; )
                                 {
                                     PhoneContent.PoneConterItems.RemoveAt(i);
                                 }
                             }
                         }
                         progressPending.Stream.Dispose();
                         progressPending = null;

                         PhoneContent.Result = 2;
                         WaitUiThread.Set();
                     });
                     WaitUiThread.WaitOne();
                 }
            }
            catch(Exception e)
            {
               
                Debug.WriteLine(e.Message);
               
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        private static void LoadMorePhoneReply()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                {

                }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                if (progressPending.ResolvingObject is PhoneInfoContentView)
                {
                    //
                    var PhoneContent = progressPending.ResolvingObject as PhoneInfoContentView;
                  
                    foreach (XElement element in xdoc.Descendants("resultinfo"))
                    {
                        //如果有错弹出错误处理;
                        int result = int.Parse(element.Attribute("result").Value);
                        string resultmsg = element.Attribute("resultmsg").Value;
                        int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                        if (0 == result)
                        {
                           // MessageBox.Show(resultmsg, "提示!", MessageBoxButton.OK);
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                PhoneContent.Result = 1;
                                PhoneContent.ResultMsg = resultmsg;
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                            return;
                        }
                    }
                    foreach (XElement element in xdoc.Element("lexun").Descendants("page"))
                    {
                        PhoneContent.CurrentPage = int.Parse(element.Attribute("p").Value);
                        PhoneContent.TotalPage = int.Parse(element.Attribute("total").Value);
                    }
                        //PhoneContent.PoneConterItems.RemoveAt(PhoneContent.PoneConterItems.Count-1);//删除掉更多那一项
                        foreach (XElement element in xdoc.Element("lexun").Descendants("reply"))
                        {
                            PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                            XmlReader xtr = element.CreateReader();
                            string currentElement = null;
                            while (xtr.Read())
                            {
                                switch (xtr.NodeType)
                                {
                                    case XmlNodeType.Element:
                                        currentElement = xtr.LocalName;
                                        if (currentElement == "topic")
                                        {//
                                            while (xtr.MoveToNextAttribute())
                                            {
                                                switch (xtr.Name)
                                                {
                                                    case "readcount":
                                                        PhoneContent.ReadCount = xtr.Value;
                                                        break;
                                                    case "rlycount":
                                                        PhoneContent.ReplyCount = xtr.Value;
                                                        break;
                                                }
                                            }
                                        }
                                        break;
                                    case XmlNodeType.CDATA:
                                    case XmlNodeType.Text:
                                        switch (currentElement)
                                        {
                                            case "writetime":
                                                infoItem.Keywords = xtr.Value;
                                                break;
                                            case "usernick":
                                                infoItem.Title = xtr.Value;
                                                break;
                                            case "content":
                                                infoItem.Content = xtr.Value;
                                                break;
                                            case "floor":
                                                infoItem.Replytime = xtr.Value;
                                                infoItem.Replytime += "楼";
                                                break;
                                        }
                                        break;
                                    default:
                                        break;
                                }

                            }
                            infoItem.Type = "Main";
                            if (infoItem.Title.Length == 0)
                                infoItem.Title = "乐友";
                            progressPending.list.Add(infoItem);
                            //PhoneContent.PoneConterItems.Add(infoItem);
                        }
                        if (PhoneContent.PoneConterItems.Count > 0)
                        {
                            if (PhoneContent.CurrentPage * PhoneContent.PageSize < PhoneContent.TotalPage)
                            {
                                PhoneInfoCenterItem infoItem = new PhoneInfoCenterItem();
                                infoItem.Title = "正在加载...";
                                infoItem.Type = "LastTitle";
                                progressPending.list.Add(infoItem);
                                //PhoneContent.PoneConterItems.Add(infoItem);
                            }
                        }
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            PhoneContent.PoneConterItems.RemoveAt(PhoneContent.PoneConterItems.Count - 1);

                            for (int i = 0; i < progressPending.list.Count; i++)
                            {
                                PhoneContent.PoneConterItems.Add((PhoneInfoCenterItem)progressPending.list[i]);
                            }

                            progressPending.Stream.Dispose();
                            progressPending = null;
                            PhoneContent.Result = 2;
                            WaitUiThread.Set();
                        });
                        WaitUiThread.WaitOne();
                    }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
        private static void LoadReplyResult()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                {

                }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                if (progressPending.ResolvingObject is ReplyResult)
                {
                    var PhoneContent = progressPending.ResolvingObject as ReplyResult;
                    foreach (XElement element in xdoc.Descendants("resultinfo"))
                    {
                        string ResultMsg = element.Attribute("resultmsg").Value;
                        int IsLogo = int.Parse(element.Attribute("isgotologin").Value);
                        int Result = int.Parse(element.Attribute("result").Value);
                        //如果有错弹出错误处理;
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            if (Result == 0)
                            {
                                PhoneContent.Result = 1;
                            }
                            else
                            {
                                PhoneContent.Result = 2;
                            }
                            PhoneContent.ResultMsg = ResultMsg;
                            PhoneContent.IsLogo = IsLogo;
                           //int.Parse(element.Attribute("result").Value);
                            WaitUiThread.Set();
                            progressPending.Stream.Dispose();
                            progressPending = null;
                        });
                        WaitUiThread.WaitOne();
                        
                    }
                }
            }
            catch(Exception e)
            {
                Debug.WriteLine(e.Message);
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        //加载精明眼,精明眼不分页所以全部缓存
        private static void LoadShrewdEye()
        {//精明眼
         // 
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                {

                }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }

                progressPending.Stream.Seek(0, SeekOrigin.Begin);
                CacheImage(progressPending.Stream, progressPending.Uri);
                //精明眼一共就一页，不加判断 全部缓存
                if (progressPending.ResolvingObject is ShrewdEyeView)
                {
                    var ShrewdEye = progressPending.ResolvingObject as ShrewdEyeView;
                    //ShrewdEye.prg.Visibility = Visibility.Collapsed;
                    foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
                    {
                        //如果有错弹出错误处理;
                        int result = int.Parse(element.Attribute("result").Value);
                        string resultmsg = element.Attribute("resultmsg").Value;
                        int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                        if (0 == result)
                        {
                            MessageBox.Show(resultmsg, "提示!", MessageBoxButton.OK);
                            progressPending.Stream.Dispose();
                            progressPending = null;
                            return;
                        }
                    }
                        foreach (XElement element in xdoc.Element("lexun").Descendants("topic"))
                        {
                            ShrewdEyeItem infoItem = new ShrewdEyeItem();
                            XmlReader xtr = element.CreateReader();
                            string currentElement = null;
                            while (xtr.Read())
                            {
                                //Debug.WriteLine("NodeType is {0},{1},{2}", xtr.NodeType, xtr.LocalName, xtr.Value);
                                switch (xtr.NodeType)
                                {
                                    case XmlNodeType.Element:
                                        currentElement = xtr.LocalName;
                                        if (xtr.LocalName == "topic")
                                        {
                                            //
                                            while (xtr.MoveToNextAttribute())
                                            {
                                                switch (xtr.Name)
                                                {
                                                    case "topicid":
                                                        infoItem.Topicid = xtr.Value;
                                                        break;
                                                    case "userid":

                                                        break;
                                                    case "ztid":

                                                        break;
                                                    case "readcount":
                                                        infoItem.Readcount = xtr.Value;
                                                        break;
                                                    case "rlycount":
                                                        infoItem.Replycount = xtr.Value;
                                                        break;

                                                }
                                            }
                                        }
                                        break;
                                    case XmlNodeType.CDATA:
                                    case XmlNodeType.Text:
                                        switch (currentElement)
                                        {
                                            case "title":
                                                infoItem.Title = xtr.Value;
                                                break;
                                            case "keywords":

                                                break;
                                            case "writetime":

                                                break;
                                            case "replytime":

                                                break;
                                            case "picurl":
                                                infoItem.Picurl = xtr.Value;
                                                break;
                                            case "content":
                                                infoItem.Content = xtr.Value;
                                                break;
                                        }
                                        break;
                                    default:
                                        break;
                                }
                            }
                            progressPending.list.Add(infoItem);
                           // ShrewdEye.ShrewdEyeItemS.Add(infoItem);
                        }
                         Deployment.Current.Dispatcher.BeginInvoke(() =>
                     {
                         if (ShrewdEye.ShrewdEyeItemS.Count == 0)
                         {
                             for (int i = 0; i < progressPending.list.Count; i++)
                             {
                                 ShrewdEye.ShrewdEyeItemS.Add((ShrewdEyeItem)progressPending.list[i]);
                             }

                         }
                         else
                         {
                             int position = 0;
                            // ShrewdEye.ShrewdEyeItemS.RemoveAt(ShrewdEye.ShrewdEyeItemS.Count - 1);
                             for (int i = 0; i < progressPending.list.Count; i++, position++)
                             {
                                 if (ShrewdEye.ShrewdEyeItemS.Count > position)
                                 {
                                     if (ShrewdEye.ShrewdEyeItemS[position].Content != ((ShrewdEyeItem)progressPending.list[position]).Content ||
                                         ShrewdEye.ShrewdEyeItemS[position].Picurl != ((ShrewdEyeItem)progressPending.list[position]).Picurl)
                                     {
                                         ShrewdEye.ShrewdEyeItemS[position] = (ShrewdEyeItem)progressPending.list[position];
                                     }
                                 }
                                 else
                                 {
                                     ShrewdEye.ShrewdEyeItemS.Add((ShrewdEyeItem)progressPending.list[position]);
                                 }

                             }
                             if (position < ShrewdEye.ShrewdEyeItemS.Count)
                             {
                                 for (int i = position; i < ShrewdEye.ShrewdEyeItemS.Count; )
                                 {
                                     ShrewdEye.ShrewdEyeItemS.RemoveAt(i);
                                 }
                             }
                         }
                         progressPending.Stream.Dispose();
                         progressPending = null;
                         ShrewdEye.IsLoadSuccess = 2;
                         WaitUiThread.Set();
                     });
                         WaitUiThread.WaitOne();
                }

            }
            catch(Exception)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        //加载搜机中心的回复
        private static void LoadFirstSearchResult()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                {}
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                if (progressPending.ResolvingObject is SearchResultView)
                {
                    var PhoneContent = progressPending.ResolvingObject as SearchResultView;                    
                        foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
                        {
                            //如果有错弹出错误处理;
                            int result = int.Parse(element.Attribute("result").Value);
                            string resultmsg = element.Attribute("resultmsg").Value;
                            int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                            if (0 == result)
                            {
                                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                {
                                    PhoneContent.Message = resultmsg;
                                    PhoneContent.Result = 1;//失败
                                    WaitUiThread.Set();
                                });
                                WaitUiThread.WaitOne();

                                progressPending.Stream.Dispose();
                                progressPending = null;
                                return;

                            }//if end                       
                        }//foreach end
                        foreach (XElement element in xdoc.Element("lexun").Descendants("keys"))
                        {
                            //如果有错弹出错误处理;                       
                            PhoneContent.Defualt = element.Element("default").Value; ;
                            PhoneContent.Key = element.Element("key").Value; ;
                        }//forea
                        foreach (XElement element in xdoc.Element("lexun").Descendants("page"))
                        {
                            PhoneContent.TotalPage = int.Parse(element.Attribute("total").Value);
                            PhoneContent.CurrentPage = int.Parse(element.Attribute("p").Value);
                        }//foreach end
                        if (PhoneContent.CurrentPage == 1)
                        {//只有第一页会缓存其余的页数都不会缓存
                            progressPending.Stream.Seek(0, SeekOrigin.Begin);
                            CacheImage(progressPending.Stream, progressPending.Uri);
                        }
                        foreach (XElement element in xdoc.Element("lexun").Descendants("phone"))
                        {
                            phonePkItem infoItem = new phonePkItem();
                            infoItem.Ponhe1_pid = element.Attribute("pid").Value;
                            infoItem.Ponhe1_phonename = element.Attribute("phonename").Value;
                            infoItem.Ponhe1_rank = element.Attribute("rank").Value;
                            infoItem.Ponhe1_forumid = element.Attribute("forumid").Value;
                            infoItem.Ponhe1_ppid = element.Attribute("ppid").Value;
                            infoItem.Ponhe1_ppname = element.Attribute("ppname").Value;
                            string price = element.Attribute("price").Value;
                            if (price.Length == 0)
                            {
                                infoItem.Ponhe1_price = "0";
                            }
                            else
                            {
                                infoItem.Ponhe1_price = price;
                            }
                            infoItem.Ponhe1_maxprice = element.Attribute("maxprice").Value;
                            infoItem.Ponhe1_minprice = element.Attribute("minprice").Value;
                            infoItem.Ponhe1_picurl = element.Element("imgurl").Value;

                            try
                            {
                                infoItem.Ponhe1_addtime = element.Attribute("addtime").Value;
                            }
                            catch (Exception)
                            { }
                            try
                            {
                                string score = element.Element("score").Value;
                                if (score.Length == 0)
                                {
                                    infoItem.Ponhe1_score = "无评级";
                                }
                                else
                                {
                                    float f_score = float.Parse(score);
                                    infoItem.Ponhe1_score = f_score.ToString("#.#");
                                }

                            }
                            catch (Exception)
                            { }

                            infoItem.Type = "Main";
                            progressPending.list.Add(infoItem);

                            //PhoneContent.SearchResultItems.Add(infoItem);
                        }//foreach end
                        if (PhoneContent.CurrentPage * PhoneContent.PageSize <= PhoneContent.TotalPage)
                        {
                            phonePkItem tailItem = new phonePkItem();
                            tailItem.Ponhe1_phonename = "正在加载更多...";
                            tailItem.Type = "Tail";
                            progressPending.list.Add(tailItem);
                            // PhoneContent.SearchResultItems.Add(tailItem);
                        }
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            if (PhoneContent.SearchResultItems.Count == 0)
                            {
                                for (int i = 0; i < progressPending.list.Count; i++)
                                {
                                    PhoneContent.SearchResultItems.Add((phonePkItem)progressPending.list[i]);
                                }

                            }
                            else
                            {
                                int position = 0;
                                //PhoneContent.SearchResultItems.RemoveAt(PhoneContent.SearchResultItems.Count - 1);
                                for (int i = 0; i < progressPending.list.Count; i++, position++)
                                {
                                    if (PhoneContent.SearchResultItems.Count > position)
                                    {
                                        if (PhoneContent.SearchResultItems[position].Ponhe1_pid != ((phonePkItem)progressPending.list[position]).Ponhe1_pid ||
                                            PhoneContent.SearchResultItems[position].Ponhe1_ppid != ((phonePkItem)progressPending.list[position]).Ponhe1_ppid)
                                        {
                                            PhoneContent.SearchResultItems[position] = (phonePkItem)progressPending.list[position];
                                        }
                                    }
                                    else
                                    {
                                        PhoneContent.SearchResultItems.Add((phonePkItem)progressPending.list[position]);
                                    }

                                }
                                if (position < PhoneContent.SearchResultItems.Count)
                                {
                                    for (int i = position; i < PhoneContent.SearchResultItems.Count; )
                                    {
                                        PhoneContent.SearchResultItems.RemoveAt(i);
                                    }
                                }
                            }
                            progressPending.Stream.Dispose();
                            progressPending = null;
                            PhoneContent.Result = 2;
                            WaitUiThread.Set();
                        });
                        WaitUiThread.WaitOne();
                    }//foreach end
                    
            }//try end
            catch(Exception)
            {
             //
                progressPending.Stream.Dispose();
                progressPending = null;

            }
        }
        private static void LoadInitResult()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                {                }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                if (progressPending.ResolvingObject is SearchResultView)
                {
                    var PhoneContent = progressPending.ResolvingObject as SearchResultView;
                    
                    foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
                    {
                        int result = int.Parse(element.Attribute("result").Value);
                        string resultmsg = element.Attribute("resultmsg").Value;
                        int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                        if (0 == result)
                        {
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                PhoneContent.Message = resultmsg;
                                PhoneContent.Result = 1;//失败
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();

                            progressPending.Stream.Dispose();
                            progressPending = null;
                           
                            return;
                        }//if end                       
                    }//foreach end
                    foreach (XElement element in xdoc.Descendants("lexun"))
                    {
                     
                        phonePkItem infoItem = new phonePkItem();
                        infoItem.Ponhe1_pid = element.Element("pid").Value;
                        infoItem.Ponhe1_ppname = element.Element("phonename").Value;
                       // infoItem.Ponhe1_ppname = 
                        infoItem.Ponhe1_forumid = element.Element("forumid").Value;
                        infoItem.Ponhe1_ppid = element.Element("ppid").Value;
                        infoItem.Ponhe1_price = "价格：" + element.Element("price").Value;
                        infoItem.Ponhe1_maxprice = element.Element("maxprice").Value;
                        infoItem.Ponhe1_minprice = element.Element("minprice").Value;
                        infoItem.Ponhe1_picurl = element.Element("imgurl").Value;
                        progressPending.list.Add(infoItem);
                        //PhoneContent.SearchResultItems.Add(infoItem);
                    }//foreach
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        //PhoneContent.SearchResultItems.RemoveAt(PhoneContent.SearchResultItems.Count - 1);

                        for (int i = 0; i < progressPending.list.Count; i++)
                        {
                           // ((phonePkItem)progressPending.list[i]).Ponhe1_ppname = QueryXml.phonename;
                            PhoneContent.SearchResultItems.Add((phonePkItem)progressPending.list[i]);
                           // MessageBox.Show(string.Format("ppname is {0}", QueryXml.phonename));
                        }

                        progressPending.Stream.Dispose();
                        progressPending = null;
                        PhoneContent.Result = 2;
                        WaitUiThread.Set();
                    });
                    WaitUiThread.WaitOne();
                }
            }
            catch (Exception)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        private static void LoadMoreSearchResult()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                if (progressPending.ResolvingObject is SearchResultView)
                {
                    var PhoneContent = progressPending.ResolvingObject as SearchResultView;
                    
                    
                    foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
                    {
                        //如果有错弹出错误处理;
                        int result = int.Parse(element.Attribute("result").Value);
                        string resultmsg = element.Attribute("resultmsg").Value;
                        int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                        if (0 == result)
                        {
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                PhoneContent.Result = 1;
                               // MessageBox.Show(resultmsg, "加载更多内容失败", MessageBoxButton.OK);
                            });
                            progressPending.Stream.Dispose();
                            progressPending = null;
                            return;

                        }//if end

                    }//foreach end
                    foreach (XElement element in xdoc.Element("lexun").Descendants("page"))
                    {
                        PhoneContent.TotalPage = int.Parse(element.Attribute("total").Value);
                        PhoneContent.CurrentPage = int.Parse(element.Attribute("p").Value);
                    }//foreach end
                   
                       // 
                        foreach (XElement element in xdoc.Element("lexun").Descendants("phone"))
                        {
                            phonePkItem infoItem = new phonePkItem();
                            infoItem.Ponhe1_pid = element.Attribute("pid").Value;
                            infoItem.Ponhe1_phonename = element.Attribute("phonename").Value;
                            infoItem.Ponhe1_rank = "评价：(" + element.Attribute("rank").Value + ")星";
                            infoItem.Ponhe1_forumid = element.Attribute("forumid").Value;
                            infoItem.Ponhe1_ppid = element.Attribute("ppid").Value;
                            infoItem.Ponhe1_ppname = element.Attribute("ppname").Value;
                            infoItem.Ponhe1_price = "价格：" + element.Attribute("price").Value;
                            infoItem.Ponhe1_maxprice = element.Attribute("maxprice").Value;
                            infoItem.Ponhe1_minprice = element.Attribute("minprice").Value;
                            infoItem.Ponhe1_picurl = element.Element("imgurl").Value;
                            infoItem.Type = "Main";
                            progressPending.list.Add(infoItem);
                           // PhoneContent.SearchResultItems.Add(infoItem);
                        }//foreach end
                        if (PhoneContent.CurrentPage * PhoneContent.PageSize <= PhoneContent.TotalPage)
                        {
                            phonePkItem tailItem = new phonePkItem();
                            tailItem.Ponhe1_phonename = "正在加载更多...";
                            tailItem.Type = "Tail";
                            progressPending.list.Add(tailItem);
                            // PhoneContent.SearchResultItems.Add(tailItem);
                        }
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        PhoneContent.SearchResultItems.RemoveAt(PhoneContent.SearchResultItems.Count - 1);

                        for (int i = 0; i < progressPending.list.Count; i++)
                        {
                            PhoneContent.SearchResultItems.Add((phonePkItem)progressPending.list[i]);
                        }

                        progressPending.Stream.Dispose();
                        progressPending = null;
                        PhoneContent.Result = 2;
                        WaitUiThread.Set();
                    });
                    WaitUiThread.WaitOne();
                }//if end


            }
            catch (Exception)
            {
                //

            }
        }
        //加载默认的机型PK
        private static void LoadDefualtPhonePK()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                if (progressPending.ResolvingObject is phonePkView)
                 {
                     var PhoneContent = progressPending.ResolvingObject as phonePkView;
                     if (PhoneContent==null)
                     {
                         return;
                     }
                     //PhoneContent.ImageVis = true;
                     foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
                     {
                         //如果有错弹出错误处理;
                         int result = int.Parse(element.Attribute("result").Value);
                         string resultmsg = element.Attribute("resultmsg").Value;
                         int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                         if (0 == result)
                         {
                             MessageBox.Show(resultmsg, "获取网络数据失败，请稍后再试", MessageBoxButton.OK);
                             return;
                         }//if end

                      }//foreach end
                     progressPending.Stream.Seek(0, SeekOrigin.Begin);
                     CacheImage(progressPending.Stream, progressPending.Uri);
                     foreach (XElement element in xdoc.Element("lexun").Descendants("pkphone"))
                     {
                         phonePkItem pkItem=new phonePkItem();
                         foreach (XElement element1 in element.Descendants("phone1"))
                         {
                             pkItem.Ponhe1_pid = element1.Attribute("pid").Value;
                             pkItem.Ponhe1_phonename= element1.Attribute("phonename").Value;
                             pkItem.Ponhe1_rank= element1.Attribute("rank").Value;
                             pkItem.Ponhe1_forumid= element1.Attribute("forumid").Value;
                             pkItem.Ponhe1_ppid = element1.Attribute("ppid").Value;
                             pkItem.Ponhe1_ppname = element1.Attribute("ppname").Value;
                             pkItem.Ponhe1_price= element1.Attribute("price").Value;
                             pkItem.Ponhe1_maxprice = element1.Attribute("maxprice").Value;
                             pkItem.Ponhe1_minprice = element1.Attribute("minprice").Value;
                             pkItem.Ponhe1_addtime = element1.Attribute("addtime").Value;
                             pkItem.Ponhe1_picurl = element1.Element("imgurl").Value;
                             pkItem.Ponhe1_score = element1.Element("score").Value;

                         }
                         foreach (XElement element2 in element.Descendants("phone2"))
                         {
                             pkItem.Ponhe2_pid       = element2.Attribute("pid").Value;
                             pkItem.Ponhe2_phonename = element2.Attribute("phonename").Value;
                             pkItem.Ponhe2_rank      = element2.Attribute("rank").Value;
                             pkItem.Ponhe2_forumid   = element2.Attribute("forumid").Value;
                             pkItem.Ponhe2_ppid      = element2.Attribute("ppid").Value;
                             pkItem.Ponhe2_ppname    = element2.Attribute("ppname").Value;
                             pkItem.Ponhe2_price     = element2.Attribute("price").Value;
                             pkItem.Ponhe2_maxprice  = element2.Attribute("maxprice").Value;
                             pkItem.Ponhe2_minprice  = element2.Attribute("minprice").Value;
                             pkItem.Ponhe2_addtime   = element2.Attribute("addtime").Value;
                             pkItem.Ponhe2_picurl    = element2.Element("imgurl").Value;
                             pkItem.Ponhe2_score     = element2.Element("score").Value;
                         }
                         progressPending.list.Add(pkItem);
                     }
                     Deployment.Current.Dispatcher.BeginInvoke(() =>
                     {
                         if (PhoneContent.PhonePkItems.Count == 0)
                         {
                             for (int i = 0; i < progressPending.list.Count; i++)
                             {
                                 PhoneContent.PhonePkItems.Add((phonePkItem)progressPending.list[i]);
                             }
                         }
                         else
                         {   int position = 0;
                             PhoneContent.PhonePkItems.RemoveAt(PhoneContent.PhonePkItems.Count - 1);
                             for (int i = 0; i < progressPending.list.Count; i++, position++)
                             {
                                 if (PhoneContent.PhonePkItems.Count > position)
                                 {
                                     if (PhoneContent.PhonePkItems[position].Ponhe1_pid != ((phonePkItem)progressPending.list[position]).Ponhe1_pid ||
                                         PhoneContent.PhonePkItems[position].Ponhe2_pid != ((phonePkItem)progressPending.list[position]).Ponhe2_pid)
                                     {
                                         PhoneContent.PhonePkItems[position] = (phonePkItem)progressPending.list[position];
                                     }
                                 }
                                 else
                                 {
                                     PhoneContent.PhonePkItems.Add((phonePkItem)progressPending.list[position]);
                                 }

                             }
                             if (position < PhoneContent.PhonePkItems.Count)
                             {
                                 for (int i = position; i < PhoneContent.PhonePkItems.Count; )
                                 {
                                     PhoneContent.PhonePkItems.RemoveAt(i);
                                 }
                             }
                         }
                         progressPending.Stream.Dispose();
                         progressPending = null;
                         PhoneContent.ImageVis = true;
                         WaitUiThread.Set();
                     });
                     WaitUiThread.WaitOne();
                  }//if end
            }
            catch(Exception)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        private static void LoadTypeParameter()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                progressPending.Stream.Seek(0, SeekOrigin.Begin);
                CacheImage(progressPending.Stream, progressPending.Uri);
                if (progressPending.ResolvingObject is TypeParameter)
                {
                    var PhoneInfoCenter = progressPending.ResolvingObject as TypeParameter;
                  
                    foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
                    {
                        int result = int.Parse(element.Attribute("result").Value);
                        string resultmsg = element.Attribute("resultmsg").Value;
                        int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                        if (0 == result)
                        {
                            MessageBox.Show(resultmsg, "获取网络数据失败，请稍后再试", MessageBoxButton.OK);
                            return;
                        }//if end

                    }//foreach end
                    Dictionary<string,int> dict = new Dictionary<string,int>();
                    dict.Add("基本属性", 1);
                    dict.Add("显示屏幕", 2);
                    dict.Add("外观设计", 3);
                    dict.Add("娱乐功能", 4);
                    dict.Add("传输功能", 5);
                    dict.Add("网络功能", 6);
                    dict.Add("短信息", 7);
                    dict.Add("商务功能", 8);
                    dict.Add("扩展性能", 9);
                    dict.Add("基本功能", 10);
                   // dict.Add("system", 11);
                   // dict.Add("screen", 12);
                   // if (PhoneInfoCenter.TypeParameterItems.Count == 0)
                   // {
                        foreach (XElement element in xdoc.Element("lexun").Descendants("phoneinfo"))
                        {
                            XmlReader xtr = element.CreateReader();
                            string currentElement = null;
                            while (xtr.Read())
                            {
                                switch (xtr.NodeType)
                                {
                                    case XmlNodeType.Element:
                                        currentElement = xtr.LocalName;

                                        //如果节点在哈希表中，则加入面节点中
                                        if (dict.ContainsKey(xtr.LocalName))
                                        {
                                            if (!xtr.IsEmptyElement)
                                            {
                                                PhoneInfoCenterItem item = new PhoneInfoCenterItem();
                                                item.Title = xtr.LocalName;
                                                item.Type = "Head";
                                                progressPending.list.Add(item);
                                                //PhoneInfoCenter.TypeParameterItems.Add(item);
                                            }

                                        }
                                        break;
                                    case XmlNodeType.Text:
                                        {
                                            if (currentElement == "system" || currentElement == "screen")
                                            {

                                            }
                                            else
                                            {
                                                 PhoneInfoCenterItem item = new PhoneInfoCenterItem();
                                                 item.Title = currentElement;
                                                 item.Content = xtr.Value;
                                                 item.Type = "Main";
                                                 progressPending.list.Add(item);
                                                 //PhoneInfoCenter.TypeParameterItems.Add(item);
                                            }                                           
                                        }
                                        break;
                                }
                            }
                        }
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            if (PhoneInfoCenter.TypeParameterItems.Count == 0)
                            {
                                for (int i = 0; i < progressPending.list.Count; i++)
                                {
                                    PhoneInfoCenter.TypeParameterItems.Add((PhoneInfoCenterItem)progressPending.list[i]);
                                }

                            }
                            else
                            {
                                int position = 0;
                               // PhoneInfoCenter.TypeParameterItems.RemoveAt(PhoneInfoCenter.TypeParameterItems.Count - 1);
                                for (int i = 0; i < progressPending.list.Count; i++, position++)
                                {
                                    if (PhoneInfoCenter.TypeParameterItems.Count > position)
                                    {
                                        if (PhoneInfoCenter.TypeParameterItems[position].Title != ((PhoneInfoCenterItem)progressPending.list[position]).Title ||
                                            PhoneInfoCenter.TypeParameterItems[position].Picurl != ((PhoneInfoCenterItem)progressPending.list[position]).Picurl)
                                        {
                                            PhoneInfoCenter.TypeParameterItems[position] = (PhoneInfoCenterItem)progressPending.list[position];
                                        }
                                    }
                                    else
                                    {
                                        PhoneInfoCenter.TypeParameterItems.Add((PhoneInfoCenterItem)progressPending.list[position]);
                                    }

                                }
                                if (position < PhoneInfoCenter.TypeParameterItems.Count)
                                {
                                    for (int i = position; i < PhoneInfoCenter.TypeParameterItems.Count; )
                                    {
                                        PhoneInfoCenter.TypeParameterItems.RemoveAt(i);
                                    }
                                }
                            }
                            progressPending.Stream.Dispose();
                            progressPending = null;
                            PhoneInfoCenter.ImageVis = true;
                            WaitUiThread.Set();
                        });
                        WaitUiThread.WaitOne();
                    
                }//最外层的if end
            }//try end
            catch(Exception)
            {

            }
        }
        private static void LoadTypePrice()
        {//
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                var PhoneContent = progressPending.ResolvingObject as TypePrice;
                foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
                {
                    int result = int.Parse(element.Attribute("result").Value);
                    string resultmsg = element.Attribute("resultmsg").Value;
                    int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                    if (0 == result)
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            PhoneContent.Result = 1;
                            WaitUiThread.Set();
                        });
                        WaitUiThread.WaitOne();
                        progressPending.Stream.Dispose();
                        progressPending = null;
                        return;
                    }
                }
                foreach (XElement element in xdoc.Element("lexun").Descendants("page"))
                {
                    PhoneContent.TotalPage = int.Parse(element.Attribute("total").Value);
                    PhoneContent.CurrentPage = int.Parse(element.Attribute("p").Value);
                }

                if (PhoneContent.CurrentPage == 1)
                {
                    progressPending.Stream.Seek(0, SeekOrigin.Begin);
                    CacheImage(progressPending.Stream, progressPending.Uri);
                }
                foreach (XElement element in xdoc.Element("lexun").Descendants("phoneprice"))
                {
                    PhoneInfoCenterItem currentItem = new PhoneInfoCenterItem();
                    //属性
                    currentItem.Keywords = element.Attribute("tel").Value;
                    currentItem.Writetime = element.Attribute("price").Value;
                    currentItem.Title = element.Element("area").Value;
                    currentItem.Content = element.Element("shop").Value;
                    currentItem.Type = "Main";
                    progressPending.list.Add(currentItem);
                }
                if (PhoneContent.CurrentPage * PhoneContent.PageSize <= PhoneContent.TotalPage)
                {
                    PhoneInfoCenterItem tailItem = new PhoneInfoCenterItem();
                    tailItem.Title = "正在加载...";
                    tailItem.Type = "Tail";
                    progressPending.list.Add(tailItem);
                }
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        if (PhoneContent.TypePriceItems.Count == 0)
                        {
                            for (int i = 0; i < progressPending.list.Count; i++)
                            {
                                PhoneContent.TypePriceItems.Add((PhoneInfoCenterItem)progressPending.list[i]);
                            }

                        }
                        else
                        {
                            int position = 0;
                            PhoneContent.TypePriceItems.RemoveAt(PhoneContent.TypePriceItems.Count - 1);
                            for (int i = 0; i < progressPending.list.Count; i++, position++)
                            {
                                if (PhoneContent.TypePriceItems.Count > position)
                                {
                                    if (PhoneContent.TypePriceItems[position].Title != ((PhoneInfoCenterItem)progressPending.list[position]).Title ||
                                        PhoneContent.TypePriceItems[position].Picurl != ((PhoneInfoCenterItem)progressPending.list[position]).Picurl)
                                    {
                                        PhoneContent.TypePriceItems[position] = (PhoneInfoCenterItem)progressPending.list[position];
                                    }
                                }
                                else
                                {
                                    PhoneContent.TypePriceItems.Add((PhoneInfoCenterItem)progressPending.list[position]);
                                }

                            }
                            if (position < PhoneContent.TypePriceItems.Count)
                            {
                                for (int i = position; i < PhoneContent.TypePriceItems.Count; )
                                {
                                    PhoneContent.TypePriceItems.RemoveAt(i);
                                }
                            }
                        }
                        progressPending.Stream.Dispose();
                        progressPending = null;
                        PhoneContent.Result = 2;
                        WaitUiThread.Set();
                    });
                    WaitUiThread.WaitOne();
            }
            catch(Exception)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        private static void LoadMoreTypePrice()
        {//加载更多
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                var PhoneContent = progressPending.ResolvingObject as TypePrice;
                foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
                {
                    int result = int.Parse(element.Attribute("result").Value);
                    string resultmsg = element.Attribute("resultmsg").Value;
                    int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                    if (0 == result)
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            PhoneContent.Result = 1;
                            WaitUiThread.Set();
                        });
                        WaitUiThread.WaitOne();
                        progressPending.Stream.Dispose();
                        progressPending = null;
                        return;
                    }
                }
                foreach (XElement element in xdoc.Element("lexun").Descendants("page"))
                {
                    PhoneContent.TotalPage = int.Parse(element.Attribute("total").Value);
                    PhoneContent.CurrentPage = int.Parse(element.Attribute("p").Value);
                }

                if (PhoneContent.CurrentPage == 1)
                {
                    progressPending.Stream.Seek(0, SeekOrigin.Begin);
                    CacheImage(progressPending.Stream, progressPending.Uri);
                }
                foreach (XElement element in xdoc.Element("lexun").Descendants("phoneprice"))
                {
                    PhoneInfoCenterItem currentItem = new PhoneInfoCenterItem();
                    //属性
                    currentItem.Keywords = element.Attribute("tel").Value;
                    currentItem.Writetime = element.Attribute("price").Value;
                    currentItem.Title = element.Element("area").Value;
                    currentItem.Content = element.Element("shop").Value;
                    currentItem.Type = "Main";
                    progressPending.list.Add(currentItem);
                }
                 if (progressPending.ResolvingObject is TypePrice)
                {
                    
                        if (PhoneContent.CurrentPage * PhoneContent.PageSize < PhoneContent.TotalPage)
                        {
                            PhoneInfoCenterItem tailItem = new PhoneInfoCenterItem();
                            tailItem.Title = "正在加载...";
                            tailItem.Type = "Tail";
                            progressPending.list.Add(tailItem);
                        }
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            PhoneContent.TypePriceItems.RemoveAt(PhoneContent.TypePriceItems.Count - 1);
                            for (int i = 0; i < progressPending.list.Count; i++)
                            {
                                PhoneContent.TypePriceItems.Add((PhoneInfoCenterItem)progressPending.list[i]);
                            }
                            progressPending.Stream.Dispose();
                            progressPending = null;
                            PhoneContent.Result = 2;
                            WaitUiThread.Set();
                        });
                        WaitUiThread.WaitOne();
                    
                }//最外层的if end
            }
            catch(Exception)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
            }
           
        }
        private static void LoadTypePicture()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                var PhoneContent = progressPending.ResolvingObject as TypePicture;
                XmlReader xtr = xdoc.CreateReader();
                if (PhoneContent == null)
                {
                    return;
                }
                //
                string currentElement = null;
                TypePictureItem currentItem = null;
                    while (xtr.Read())
                    {
                        switch (xtr.NodeType)
                        {
                            case XmlNodeType.Element:
                                {
                                    currentElement = xtr.LocalName;
                                    switch (xtr.LocalName)
                                    {
                                        case "resultinfo":
                                            {
                                                int result = 0; ;
                                                string resultmsg = "";
                                                int isgotologin = 0;
                                                while (xtr.MoveToNextAttribute())
                                                {
                                                    switch (xtr.Name)
                                                    {
                                                        case "result":
                                                            result = int.Parse(xtr.Value);
                                                            break;
                                                        case "resultmsg":
                                                            resultmsg = xtr.Value;
                                                            break;
                                                        case "isgotologin":
                                                            isgotologin = int.Parse(xtr.Value);
                                                            break;
                                                    }
                                                }
                                                if (0 == result)
                                                {
                                                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                    {
                                                        PhoneContent.Result = 1;
                                                        WaitUiThread.Set();
                                                    });
                                                    WaitUiThread.WaitOne();
                                                    progressPending.Stream.Dispose();
                                                    progressPending = null;
                                                    return;
                                                }//if end
                                            }
                                            break;
                                        case "page":
                                            while (xtr.MoveToNextAttribute())
                                            {
                                                switch (xtr.Name)
                                                {
                                                    case "total":
                                                        PhoneContent.TotalPage = int.Parse(xtr.Value);
                                                        break;
                                                    case "p":
                                                        PhoneContent.CurrentPage = int.Parse(xtr.Value);
                                                        if (PhoneContent.CurrentPage == 1)
                                                            //{//从网络下载下来的才缓存
                                                            progressPending.Stream.Seek(0, SeekOrigin.Begin);
                                                        CacheImage(progressPending.Stream, progressPending.Uri);
                                                        // }
                                                        break;
                                                }
                                            }
                                            break;
                                        case "image":
                                            currentItem = new TypePictureItem();
                                            while (xtr.MoveToNextAttribute())
                                            {
                                                switch (xtr.Name)
                                                {
                                                    case "imgageid":
                                                        currentItem.Imgageid = int.Parse(xtr.Value);
                                                        break;

                                                }
                                            }
                                            break;
                                    }
                                }
                                break;
                            case XmlNodeType.CDATA:
                            case XmlNodeType.Text:
                                switch (currentElement)
                                {
                                    case "prevurl":
                                        if (currentItem != null)
                                        {
                                            currentItem.Prevurl = xtr.Value;
                                        }
                                        break;
                                    case "acturl":
                                        if (currentItem != null)
                                        {
                                            currentItem.Acturl = xtr.Value;
                                        }
                                        break;
                                }
                                break;
                            case XmlNodeType.EndElement:
                                if (xtr.LocalName == "image")
                                {
                                    //将其item添加进来
                                    if (currentItem != null)
                                    {
                                        progressPending.list.Add(currentItem);
                                       // PhoneContent.TypePictureItems.Add(currentItem);
                                    }

                                }
                                break;
                        }
                    }//while end
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        if (PhoneContent.TypePictureItems.Count == 0)
                        {
                            for (int i = 0; i < progressPending.list.Count; i++)
                            {
                                PhoneContent.TypePictureItems.Add((TypePictureItem)progressPending.list[i]);
                            }

                        }
                        else
                        {
                            int position = 0;
                            //PhoneContent.TypePictureItems.RemoveAt(PhoneContent.TypePictureItems.Count - 1);
                            for (int i = 0; i < progressPending.list.Count; i++, position++)
                            {
                                if (PhoneContent.TypePictureItems.Count > position)
                                {
                                    if (
                                        PhoneContent.TypePictureItems[position].Prevurl != ((TypePictureItem)progressPending.list[position]).Prevurl)
                                    {
                                        PhoneContent.TypePictureItems[position] = (TypePictureItem)progressPending.list[position];
                                    }
                                }
                                else
                                {
                                    PhoneContent.TypePictureItems.Add((TypePictureItem)progressPending.list[position]);
                                }

                            }
                            if (position < PhoneContent.TypePictureItems.Count)
                            {
                                for (int i = position; i < PhoneContent.TypePictureItems.Count; )
                                {
                                    PhoneContent.TypePictureItems.RemoveAt(i);
                                }
                            }
                        }
                        progressPending.Stream.Dispose();
                        progressPending = null;
                        PhoneContent.Result = 2;
                        PhoneContent.ImageVis = true;
                        WaitUiThread.Set();
                    });
                    WaitUiThread.WaitOne();
               // }
                //else
                //{
                //    int pos = 0;
                   
                //    if (pos < PhoneContent.TypePictureItems.Count)
                //    {
                //        for (int i = pos; i < PhoneContent.TypePictureItems.Count; i++)
                //        {
                //            PhoneContent.TypePictureItems.RemoveAt(i);
                //        }
                //    }
                //    //成功了
                //    PhoneContent.Result = 2;
                //}
            }
            catch(Exception)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
            }
          

        }
        private static void LoadTypeComment()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                XmlReader xtr = xdoc.CreateReader();
                var PhoneContent = progressPending.ResolvingObject as TypeCommentView;
                if (PhoneContent == null)
                {
                    return;
                }
             
                string currentElement = null;
                TypeCommentItem currentItem = null;
                    while (xtr.Read())
                    {
                        switch (xtr.NodeType)
                        {
                            case XmlNodeType.Element:
                                {
                                    currentElement = xtr.LocalName;
                                    switch (xtr.LocalName)
                                    {

                                        case "resultinfo":
                                            {
                                                int result = 0; ;
                                                
                                                while (xtr.MoveToNextAttribute())
                                                {
                                                    switch (xtr.Name)
                                                    {
                                                        case "result":
                                                            result=int.Parse(xtr.Value);
                                                            if (result==0)
                                                            {
                                                                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                                {

                                                                    PhoneContent.Result = 1;
                                                                       
                                                                });
                                                                progressPending.Stream.Dispose();
                                                                progressPending = null;
                                                                return;
                                                            }
                                                            break;
                                                    }
                                                }
                                               
                                            }
                                            break;
                                       
                                        case "page":
                                            while (xtr.MoveToNextAttribute())
                                            {
                                                switch (xtr.Name)
                                                {
                                                    case "total":
                                                        PhoneContent.TotalPage = int.Parse(xtr.Value);
                                                        break;
                                                    case "p":
                                                        PhoneContent.CurrentPage = int.Parse(xtr.Value);
                                                        if (PhoneContent.CurrentPage == 1)
                                                        {//从网络下载下来的才缓存
                                                            progressPending.Stream.Seek(0, SeekOrigin.Begin);
                                                            CacheImage(progressPending.Stream, progressPending.Uri);
                                                        }
                                                        break;
                                                    case "avgscore":
                                                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                        {
                                                            PhoneContent.Avgscore = xtr.Value;
                                                            WaitUiThread.Set();
                                                        });
                                                        WaitUiThread.WaitOne();
                                                        break;

                                                }
                                            }
                                            break;
                                        case "evaluate":
                                            currentItem = new TypeCommentItem();
                                            while (xtr.MoveToNextAttribute())
                                            {
                                                switch (xtr.Name)
                                                {
                                                    case "id":
                                                        currentItem.Id = int.Parse(xtr.Value);
                                                        break;
                                                    case "floor":
                                                        currentItem.Floor = xtr.Value + "楼";
                                                        break;
                                                    case "support":
                                                        currentItem.Support = int.Parse(xtr.Value);
                                                        break;
                                                    case "oppose":
                                                        currentItem.Oppose = int.Parse(xtr.Value);
                                                        break;
                                                    case "score":
                                                        currentItem.Score = xtr.Value + "分";
                                                        break;
                                                    case "userid":
                                                        currentItem.Userid = int.Parse(xtr.Value);
                                                        break;
                                                }
                                            }
                                            break;
                                    }
                                }
                                break;
                            case XmlNodeType.CDATA:
                            case XmlNodeType.Text:
                                switch (currentElement)
                                {
                                    case "nick":
                                        if (currentItem != null)
                                        {
                                            currentItem.Nick = xtr.Value;
                                        }
                                        break;
                                    case "advant":
                                        if (currentItem != null)
                                        {
                                            currentItem.Advant = xtr.Value;
                                        }
                                        break;
                                    case "defect":
                                        if (currentItem != null)
                                        {
                                            currentItem.Defect = xtr.Value;
                                        }
                                        break;
                                    case "addtime":
                                        if (currentItem != null)
                                        {
                                            currentItem.Addtime = xtr.Value;
                                        }
                                        break;

                                    case "avgscore":
                                         Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                    {
                                                        PhoneContent.Avgscore = xtr.Value;
                                                        WaitUiThread.Set();
                                                    });
                                                    WaitUiThread.WaitOne();
                                        break;
                                }
                                break;
                            case XmlNodeType.EndElement:
                                if (xtr.LocalName == "evaluate")
                                {
                                    //将其item添加进来
                                    if (currentItem != null)
                                    {
                                        currentItem.Type = "Head";
                                        //PhoneContent.TypeCommentItems.Add(currentItem);
                                        progressPending.list.Add(currentItem);
                                    }

                                }
                                break;
                        }
                    }//while end
                
                if (PhoneContent.CurrentPage * PhoneContent.PageSize < PhoneContent.TotalPage)
                {
                    TypeCommentItem tailItem = new TypeCommentItem();
                    tailItem.Type = "Tail";
                    tailItem.Addtime = "正在添加...";
                    progressPending.list.Add(tailItem);

                    //PhoneContent.TypeCommentItems.Add();
                }
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    if (PhoneContent.TypeCommentItems.Count == 0)
                    {
                        for (int i = 0; i < progressPending.list.Count; i++)
                        {
                            PhoneContent.TypeCommentItems.Add((TypeCommentItem)progressPending.list[i]);
                        }

                    }
                    else
                    {
                        int position = 0;
                        PhoneContent.TypeCommentItems.RemoveAt(PhoneContent.TypeCommentItems.Count - 1);
                        for (int i = 0; i < progressPending.list.Count; i++, position++)
                        {
                            if (PhoneContent.TypeCommentItems.Count > position)
                            {
                                if (
                                    PhoneContent.TypeCommentItems[position].Addtime != ((TypeCommentItem)progressPending.list[position]).Addtime)
                                {
                                    PhoneContent.TypeCommentItems[position] = (TypeCommentItem)progressPending.list[position];
                                }
                            }
                            else
                            {
                                PhoneContent.TypeCommentItems.Add((TypeCommentItem)progressPending.list[position]);
                            }

                        }
                        if (position < PhoneContent.TypeCommentItems.Count)
                        {
                            for (int i = position; i < PhoneContent.TypeCommentItems.Count; )
                            {
                                PhoneContent.TypeCommentItems.RemoveAt(i);
                            }
                        }
                       
                    }
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    PhoneContent.Result = 2;
                    WaitUiThread.Set();
                });
                WaitUiThread.WaitOne();

            }
            catch(Exception)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
            }
           
         

        }
        private static void LoadMoreTypeComment()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                var PhoneContent = progressPending.ResolvingObject as TypeCommentView;
                XmlReader xtr = xdoc.CreateReader();
                if (PhoneContent == null)
                {
                    return;
                }

                
                string currentElement = null;
                TypeCommentItem currentItem = null;
                if (PhoneContent.TypeCommentItems.Count != 0)
                {
                

                    while (xtr.Read())
                    {
                        switch (xtr.NodeType)
                        {
                            case XmlNodeType.Element:
                                {
                                    currentElement = xtr.LocalName;
                                    switch (xtr.LocalName)
                                    {
                                        case "resultinfo":
                                            {
                                                int result = 0; ;
                                                string resultmsg = "";
                                                int isgotologin = 0;
                                                while (xtr.MoveToNextAttribute())
                                                {
                                                    switch (xtr.Name)
                                                    {
                                                        case "result":
                                                            result = int.Parse(xtr.Value);
                                                            break;
                                                        case "resultmsg":
                                                            resultmsg = xtr.Value;
                                                            break;
                                                        case "isgotologin":
                                                            isgotologin = int.Parse(xtr.Value);
                                                            break;
                                                    }
                                                }
                                                if (0 == result)
                                                {
                                                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                    {
                                                        MessageBox.Show(resultmsg, "提示！", MessageBoxButton.OK);
                                                        PhoneContent.Result = 1;
                                                        WaitUiThread.Set();
                                                    });
                                                    WaitUiThread.WaitOne();
                                                    progressPending.Stream.Dispose();
                                                    progressPending = null;
                                                    return;
                                                }//if end
                                            }
                                            break;
                                        case "page":
                                            while (xtr.MoveToNextAttribute())
                                            {
                                                switch (xtr.Name)
                                                {
                                                    case "total":
                                                          Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                    {
                                                        PhoneContent.TotalPage = int.Parse(xtr.Value);
                                                        WaitUiThread.Set();
                                                    });
                                                    WaitUiThread.WaitOne();
                                                    
                                                        break;
                                                    case "p":
                                                         Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                    {
                                                        PhoneContent.CurrentPage = int.Parse(xtr.Value);
                                                        WaitUiThread.Set();
                                                    });
                                                    WaitUiThread.WaitOne();
                                                       
                                                        break;
                                                    case "avgscore":
                                                         Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                    {
                                                        PhoneContent.Avgscore = xtr.Value;
                                                        WaitUiThread.Set();
                                                    });
                                                    WaitUiThread.WaitOne();
                                                       
                                                        break;
                                                }
                                            }
                                            break;
                                        case "evaluate":
                                            currentItem = new TypeCommentItem();
                                            while (xtr.MoveToNextAttribute())
                                            {
                                                switch (xtr.Name)
                                                {
                                                    case "id":
                                                        currentItem.Id = int.Parse(xtr.Value);
                                                        break;
                                                    case "floor":
                                                        currentItem.Floor = xtr.Value + "楼";
                                                        break;
                                                    case "support":
                                                        currentItem.Support = int.Parse(xtr.Value);
                                                        break;
                                                    case "oppose":
                                                        currentItem.Oppose = int.Parse(xtr.Value);
                                                        break;
                                                    case "score":
                                                        currentItem.Score = xtr.Value + "分";
                                                        break;
                                                    case "userid":
                                                        currentItem.Userid = int.Parse(xtr.Value);
                                                        break;
                                                }
                                            }
                                            break;
                                    }
                                }
                                break;
                            case XmlNodeType.CDATA:
                            case XmlNodeType.Text:
                                switch (currentElement)
                                {
                                    case "nick":
                                        if (currentItem != null)
                                        {
                                            currentItem.Nick = xtr.Value;
                                        }
                                        break;
                                    case "advant":
                                        if (currentItem != null)
                                        {
                                            currentItem.Advant = xtr.Value;
                                        }
                                        break;
                                    case "defect":
                                        if (currentItem != null)
                                        {
                                            currentItem.Defect = xtr.Value;
                                        }
                                        break;
                                    case "addtime":
                                        if (currentItem != null)
                                        {
                                            currentItem.Addtime = xtr.Value;
                                        }
                                        break;
                                    case "avgscore":

                                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                    {
                                                        PhoneContent.Avgscore = xtr.Value;
                                                        WaitUiThread.Set();
                                                    });
                                                    WaitUiThread.WaitOne();

                                        break;
                                }
                                break;
                            case XmlNodeType.EndElement:
                                if (xtr.LocalName == "evaluate")
                                {
                                    //将其item添加进来
                                    if (currentItem != null)
                                    {
                                        currentItem.Type = "Head";
                                        progressPending.list.Add(currentItem);
                                       // PhoneContent.TypeCommentItems.Add(currentItem);
                                    }

                                }
                                break;
                        }
                    }//while end
                    if (PhoneContent.CurrentPage * PhoneContent.PageSize <= PhoneContent.TotalPage)
                    {
                        TypeCommentItem tailItem = new TypeCommentItem();
                        tailItem.Addtime = "正在添加...";
                        tailItem.Type = "Tail";
                        progressPending.list.Add(tailItem);
                       // PhoneContent.TypeCommentItems.Add(tailItem);
                    }
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        PhoneContent.TypeCommentItems.RemoveAt(PhoneContent.TypeCommentItems.Count - 1);

                        for (int i = 0; i < progressPending.list.Count; i++)
                        {
                            PhoneContent.TypeCommentItems.Add((TypeCommentItem)progressPending.list[i]);
                        }
                        progressPending.Stream.Dispose();
                        progressPending = null;
                        PhoneContent.Result=2;
                        WaitUiThread.Set();
                    });
                    WaitUiThread.WaitOne();
                }
             }
            catch(Exception)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
            }
           
        }
        private static void LoadScoreDetail()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                if (progressPending.ResolvingObject is ScoreDetail)
                {
                    var PhoneContent = progressPending.ResolvingObject as ScoreDetail;
                    XmlReader xtr = xdoc.CreateReader();
                    string currentElement = null;
                    while (xtr.Read())
                    {
                        switch (xtr.NodeType)
                        {
                            case XmlNodeType.Element:
                                {
                                    currentElement = xtr.LocalName;
                                    switch (xtr.LocalName)
                                    {
                                        case "resultinfo":
                                            {
                                                int result = 0; ;
                                                string resultmsg = "";
                                                int isgotologin = 0;
                                                while (xtr.MoveToNextAttribute())
                                                {
                                                    switch (xtr.Name)
                                                    {
                                                        case "result":
                                                            result = int.Parse(xtr.Value);
                                                            break;
                                                        case "resultmsg":
                                                            resultmsg = xtr.Value;
                                                            break;
                                                        case "isgotologin":
                                                            isgotologin = int.Parse(xtr.Value);
                                                            break;
                                                    }
                                                }
                                                if (0 == result)
                                                {
                                                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                    {
                                                        MessageBox.Show(resultmsg, "提示！", MessageBoxButton.OK);
                                                        WaitUiThread.Set();
                                                    });
                                                    WaitUiThread.WaitOne();
                                                    progressPending.Stream.Dispose();
                                                    progressPending = null;
                                                    return;
                                                }//if end
                                            }
                                            break;
                                        case "score":
                                            break;
                                    }
                                }
                                break;
                            case XmlNodeType.CDATA:
                            case XmlNodeType.Text:
                                switch (currentElement)
                                {
                                    case "sc1":
                                        PhoneContent.Sc1 = int.Parse(xtr.Value);
                                        break;
                                    case "sc2":
                                        PhoneContent.Sc2 = int.Parse(xtr.Value);
                                        break;
                                    case "sc3":
                                        PhoneContent.Sc3 = int.Parse(xtr.Value);
                                        break;
                                    case "sc4":
                                        PhoneContent.Sc4 = int.Parse(xtr.Value);
                                        break;
                                    case "sc5":
                                        PhoneContent.Sc5 = int.Parse(xtr.Value);
                                        break;
                                }
                                break;
                        }
                    }//while end
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        PhoneContent.TotalScore = PhoneContent.Sc1 + PhoneContent.Sc2 + PhoneContent.Sc3 + PhoneContent.Sc4 + PhoneContent.Sc5;

                        progressPending.Stream.Dispose();
                        progressPending = null;
                        WaitUiThread.Set();

                    });
                    WaitUiThread.WaitOne();

                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        private static void LoadTypeBible()
        {//
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                XmlReader xtr = xdoc.CreateReader();
                if (progressPending.ResolvingObject is BibleView)
                {
                    var PhoneContent = progressPending.ResolvingObject as BibleView;
                  
                    string currentElement = null;
                    PhoneInfoCenterItem currentItem = null;
                        while (xtr.Read())
                        {
                            switch (xtr.NodeType)
                            {
                                case XmlNodeType.Element:
                                    {
                                        currentElement = xtr.LocalName;
                                        switch (xtr.LocalName)
                                        {
                                            case "resultinfo":
                                                {
                                                    int result = 0; ;
                                                    string resultmsg = "";
                                                    int isgotologin = 0;
                                                    while (xtr.MoveToNextAttribute())
                                                    {
                                                        switch (xtr.Name)
                                                        {
                                                            case "result":
                                                                result = int.Parse(xtr.Value);
                                                                break;
                                                            case "resultmsg":
                                                                resultmsg = xtr.Value;
                                                                break;
                                                            case "isgotologin":
                                                                isgotologin = int.Parse(xtr.Value);
                                                                break;
                                                        }
                                                    }
                                                    if (0 == result)
                                                    {  //这样显然不友好
                                                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                        {
                                                            PhoneContent.Result = 1; 
                                                            WaitUiThread.Set();
                                                        });
                                                        WaitUiThread.WaitOne();
                                                        progressPending.Stream.Dispose();
                                                        progressPending = null;
                                                        // MessageBox.Show(resultmsg, "提示！", MessageBoxButton.OK);
                                                        return;
                                                    }  //if end
                                                   
                                                
                                                }
                                                break;
                                            case "page":
                                                while (xtr.MoveToNextAttribute())
                                                {
                                                    switch (xtr.Name)
                                                    {
                                                        case "total":
                                                            PhoneContent.TotalPage = int.Parse(xtr.Value);
                                                            break;
                                                        case "p":
                                                            PhoneContent.CurrentPage = int.Parse(xtr.Value);
                                                            if (PhoneContent.CurrentPage == 1)
                                                            {//从网络下载下来的才缓存
                                                                progressPending.Stream.Seek(0, SeekOrigin.Begin);
                                                                CacheImage(progressPending.Stream, progressPending.Uri);
                                                            }
                                                            break;
                                                    }
                                                }
                                                break;
                                            case "topic":
                                                currentItem = new PhoneInfoCenterItem();
                                                while (xtr.MoveToNextAttribute())
                                                {
                                                    switch (xtr.Name)
                                                    {
                                                        case "topicid":
                                                            currentItem.Topicid = xtr.Value;
                                                            break;
                                                        case "userid":
                                                            currentItem.Userid = xtr.Value;
                                                            break;
                                                        case "ztid":
                                                            currentItem.Ztid = xtr.Value;
                                                            break;
                                                        case "readcount":
                                                            currentItem.Readcount = xtr.Value;
                                                            break;
                                                        case "rlycount":
                                                            currentItem.Replycount = xtr.Value;
                                                            break;
                                                    }
                                                }

                                                break;
                                        }
                                    }
                                    break;
                                case XmlNodeType.CDATA:
                                case XmlNodeType.Text:
                                    switch (currentElement)
                                    {
                                        case "title":
                                            if (currentItem != null)
                                            {
                                                currentItem.Title = xtr.Value;
                                            }
                                            break;
                                        case "keywords":
                                            if (currentItem != null)
                                            {
                                                currentItem.Keywords = xtr.Value;
                                            }
                                            break;
                                        case "writetime":
                                            if (currentItem != null)
                                            {
                                                currentItem.Writetime = xtr.Value;
                                            }
                                            break;
                                        case "replytime":
                                            if (currentItem != null)
                                            {
                                                currentItem.Replytime = xtr.Value;
                                            }
                                            break;
                                    }
                                    break;
                                case XmlNodeType.EndElement:
                                    if (xtr.LocalName == "topic")
                                    {
                                        //将其item添加进来
                                        if (currentItem != null)
                                        {
                                            currentItem.Type = "Head";
                                            progressPending.list.Add(currentItem);
                                           // PhoneContent.PoneBibleViewItems.Add(currentItem);
                                            
                                        }

                                    }
                                    break;
                            }
                        }//while end
                        

                   
                    
                    if (PhoneContent.CurrentPage * PhoneContent.PageSize <= PhoneContent.TotalPage)
                    {
                        PhoneInfoCenterItem tailItem = new PhoneInfoCenterItem();
                        tailItem.Title = "正在加载...";
                        tailItem.Type = "Tail";
                        progressPending.list.Add(currentItem);
                       // PhoneContent.PoneBibleViewItems.Add(tailItem);
                    }
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        if (PhoneContent.PoneBibleViewItems.Count == 0)
                        {
                            for (int i = 0; i < progressPending.list.Count; i++)
                            {
                                PhoneContent.PoneBibleViewItems.Add((PhoneInfoCenterItem)progressPending.list[i]);
                            }

                        }
                        else
                        {
                            int position = 0;
                            PhoneContent.PoneBibleViewItems.RemoveAt(PhoneContent.PoneBibleViewItems.Count - 1);
                            for (int i = 0; i < progressPending.list.Count; i++, position++)
                            {
                                if (PhoneContent.PoneBibleViewItems.Count > position)
                                {
                                    if (PhoneContent.PoneBibleViewItems[position].Topicid != ((PhoneInfoCenterItem)progressPending.list[position]).Topicid)
                                       
                                    {
                                        PhoneContent.PoneBibleViewItems[position] = (PhoneInfoCenterItem)progressPending.list[position];
                                    }
                                }
                                else
                                {
                                    PhoneContent.PoneBibleViewItems.Add((PhoneInfoCenterItem)progressPending.list[position]);
                                }

                            }
                            if (position < PhoneContent.PoneBibleViewItems.Count)
                            {
                                for (int i = position; i < PhoneContent.PoneBibleViewItems.Count; )
                                {
                                    PhoneContent.PoneBibleViewItems.RemoveAt(i);
                                }
                            }
                        }
                        progressPending.Stream.Dispose();
                        progressPending = null;
                        PhoneContent.Result = 2;
                        WaitUiThread.Set();
                    });
                    WaitUiThread.WaitOne();
                }//if end
            }
            catch (Exception)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
              
            }
        }
        private static void LoadMoreTypeBible()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                XmlReader xtr = xdoc.CreateReader();
                if (progressPending.ResolvingObject is BibleView)
                {
                    var PhoneContent = progressPending.ResolvingObject as BibleView;
                   
                    string currentElement = null;
                    PhoneInfoCenterItem currentItem = null;
                    if (PhoneContent.PoneBibleViewItems.Count != 0)
                    {

                        while (xtr.Read())
                        {
                            switch (xtr.NodeType)
                            {
                                case XmlNodeType.Element:
                                    {
                                        currentElement = xtr.LocalName;
                                        switch (xtr.LocalName)
                                        {
                                            case "resultinfo":
                                                {
                                                    int result = 0; ;
                                                    string resultmsg = "";
                                                    int isgotologin = 0;
                                                    while (xtr.MoveToNextAttribute())
                                                    {
                                                        switch (xtr.Name)
                                                        {
                                                            case "result":
                                                                result = int.Parse(xtr.Value);
                                                                break;
                                                            case "resultmsg":
                                                                resultmsg = xtr.Value;
                                                                break;
                                                            case "isgotologin":
                                                                isgotologin = int.Parse(xtr.Value);
                                                                break;
                                                        }
                                                    }
                                                    if (0 == result)
                                                    {
                                                        progressPending.Stream.Dispose();
                                                        progressPending = null;
                                                        MessageBox.Show(resultmsg, "提示！", MessageBoxButton.OK);
                                                        return;
                                                    }//if end
                                                }
                                                break;
                                            case "page":
                                                while (xtr.MoveToNextAttribute())
                                                {
                                                    switch (xtr.Name)
                                                    {
                                                        case "total":
                                                            PhoneContent.TotalPage = int.Parse(xtr.Value);
                                                            break;
                                                        case "p":
                                                            PhoneContent.CurrentPage = int.Parse(xtr.Value);
                                                            break;
                                                    }
                                                }
                                                break;
                                            case "topic":
                                                currentItem = new PhoneInfoCenterItem();
                                                while (xtr.MoveToNextAttribute())
                                                {
                                                    switch (xtr.Name)
                                                    {
                                                        case "topicid":
                                                            currentItem.Topicid = xtr.Value;
                                                            break;
                                                        case "userid":
                                                            currentItem.Userid = xtr.Value;
                                                            break;
                                                        case "ztid":
                                                            currentItem.Ztid = xtr.Value;
                                                            break;
                                                        case "readcount":
                                                            currentItem.Readcount = xtr.Value;
                                                            break;
                                                        case "rlycount":
                                                            currentItem.Replycount = xtr.Value;
                                                            break;
                                                    }
                                                }
                                                break;
                                        }
                                    }
                                    break;
                                case XmlNodeType.CDATA:
                                case XmlNodeType.Text:
                                    switch (currentElement)
                                    {
                                        case "title":
                                            if (currentItem != null)
                                            {
                                                currentItem.Title = xtr.Value;
                                            }
                                            break;
                                        case "keywords":
                                            if (currentItem != null)
                                            {
                                                currentItem.Keywords = xtr.Value;
                                            }
                                            break;
                                        case "writetime":
                                            if (currentItem != null)
                                            {
                                                currentItem.Writetime = xtr.Value;
                                            }
                                            break;
                                        case "replytime":
                                            if (currentItem != null)
                                            {
                                                currentItem.Replytime = xtr.Value;
                                            }
                                            break;
                                    }
                                    break;
                                case XmlNodeType.EndElement:
                                    if (xtr.LocalName == "topic")
                                    {
                                        //将其item添加进来
                                        if (currentItem != null)
                                        {
                                            currentItem.Type = "Head";
                                            progressPending.list.Add(currentItem);
                                            //PhoneContent.PoneBibleViewItems.Add(currentItem);
                                        }

                                    }
                                    break;
                            }
                        }//while end
                        if (PhoneContent.CurrentPage * PhoneContent.PageSize <= PhoneContent.TotalPage)
                        {
                            PhoneInfoCenterItem tailItem = new PhoneInfoCenterItem();
                            tailItem.Title = "正在加载...";
                            tailItem.Type = "Tail";
                            progressPending.list.Add(tailItem);
                            //PhoneContent.PoneBibleViewItems.Add(tailItem);
                        }
                    }
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        PhoneContent.PoneBibleViewItems.RemoveAt(PhoneContent.PoneBibleViewItems.Count - 1);

                        for (int i = 0; i < progressPending.list.Count; i++)
                        {
                            PhoneContent.PoneBibleViewItems.Add((PhoneInfoCenterItem)progressPending.list[i]);
                        }

                        progressPending.Stream.Dispose();
                        progressPending = null;
                        PhoneContent.Result = 2;
                        WaitUiThread.Set();
                    });
                    WaitUiThread.WaitOne();
                }
            }
            catch (Exception)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        private static void LoadPhonePkParameter()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                progressPending.Stream.Seek(0, SeekOrigin.Begin);
                CacheImage(progressPending.Stream, progressPending.Uri);

                if (progressPending.ResolvingObject is PhonePkDetail)
                {
                    var PhoneInfoCenter = progressPending.ResolvingObject as PhonePkDetail;
                   
                    foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
                    {
                        //如果有错弹出错误处理;
                        int result = int.Parse(element.Attribute("result").Value);
                        string resultmsg = element.Attribute("resultmsg").Value;
                        int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                        if (0 == result)
                        {
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                PhoneInfoCenter.IsShowError = true; ;
                                WaitUiThread.Set();
                            });
                            WaitUiThread.WaitOne();
                            progressPending.Stream.Dispose();
                            progressPending = null;
                            return;
                        }//if end
                    }//foreach end
                    Dictionary<string, int> dict = new Dictionary<string, int>();
                    dict.Add("基本属性", 1);
                    dict.Add("显示屏幕", 2);
                    dict.Add("外观设计", 3);
                    dict.Add("娱乐功能", 4);
                    dict.Add("传输功能", 5);
                    dict.Add("网络功能", 6);
                    dict.Add("短信息", 7);
                    dict.Add("商务功能", 8);
                    dict.Add("扩展性能", 9);
                    dict.Add("基本功能", 10);
                    //dict.Add("system", 11);
                    //dict.Add("screen", 12);
                    PhonePkDetailItem currentElement = null;
                    string currentLocalName = null;
                    if (PhoneInfoCenter.TypeParameterItems.Count == 0)
                    {
                        foreach (XElement element in xdoc.Element("lexun").Descendants("phoneinfo"))
                        {
                            XmlReader xtr = element.CreateReader();
                        
                            while (xtr.Read())
                            {
                                switch (xtr.NodeType)
                                {
                                    case XmlNodeType.Element:
                                        currentLocalName = xtr.LocalName;

                                        //如果节点在哈希表中，则加入面节点中
                                        if (dict.ContainsKey(xtr.LocalName))
                                        {
                                            PhonePkDetailItem item = new PhonePkDetailItem();
                                                item.Title = xtr.LocalName;
                                                item.Type = "Head";
                                                progressPending.list.Add(item);
                                               // PhoneInfoCenter.TypeParameterItems.Add(item);
                                        }
                                        else//否则为普通节点
                                        {
                                            if (currentLocalName != "system" && currentLocalName != "screen" && currentLocalName != "phoneinfo")
                                            {
                                                PhonePkDetailItem item = new PhonePkDetailItem();
                                                currentElement = item;
                                                item.Title = xtr.LocalName;
                                                item.Type = "Main";
                                            }

                                          
                                        }
                                        break;
                                    case XmlNodeType.Text:
                                        {
                                           // PhoneInfoCenterItem item = new PhoneInfoCenterItem();
                                            if (currentLocalName != "system" && currentLocalName != "screen" && currentLocalName != "phoneinfo")
                                            {
                                                currentElement.Title = currentLocalName;
                                                currentElement.Content = xtr.Value;
                                                //currentElement.Type = "Main";
                                            }
                                        }
                                        break;
                                    case XmlNodeType.EndElement:
                                        if (currentLocalName != "system" && currentLocalName != "screen")
                                        {
                                            progressPending.list.Add(currentElement);
                                           // PhoneInfoCenter.TypeParameterItems.Add(currentElement);
                                        }
                                        break;
                                }
                            }
                        }
                        
                    }
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        if (PhoneInfoCenter.TypeParameterItems.Count == 0)
                        {
                            for (int i = 0; i < progressPending.list.Count; i++)
                            {
                                PhoneInfoCenter.TypeParameterItems.Add((PhonePkDetailItem)progressPending.list[i]);
                            }

                        }
                        else
                        {
                            int position = 0;
                           // PhoneInfoCenter.PoneInfoCenterItems.RemoveAt(PhoneInfoCenter.PoneInfoCenterItems.Count - 1);
                            for (int i = 0; i < progressPending.list.Count; i++, position++)
                            {
                                if (PhoneInfoCenter.TypeParameterItems.Count > position)
                                {
                                    if (PhoneInfoCenter.TypeParameterItems[position].Title != ((PhonePkDetailItem)progressPending.list[position]).Title ||
                                        PhoneInfoCenter.TypeParameterItems[position].Type != ((PhonePkDetailItem)progressPending.list[position]).Type)
                                    {
                                        PhoneInfoCenter.TypeParameterItems[position] = (PhonePkDetailItem)progressPending.list[position];
                                    }
                                }
                                else
                                {
                                    PhoneInfoCenter.TypeParameterItems.Add((PhonePkDetailItem)progressPending.list[position]);
                                }

                            }
                            if (position < PhoneInfoCenter.TypeParameterItems.Count)
                            {
                                for (int i = position; i < PhoneInfoCenter.TypeParameterItems.Count; )
                                {
                                    PhoneInfoCenter.TypeParameterItems.RemoveAt(i);
                                }
                            }
                        }
                        progressPending.Stream.Dispose();
                        progressPending = null;
                        PhoneInfoCenter.IsLoaded = true;
                        WaitUiThread.Set();
                    });
                    WaitUiThread.WaitOne();
                  
                }//最外层的if end
            }//try end
            catch (Exception)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        private static void LoadPhonePkVote()
        {
            try
            {

                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                if (progressPending.ResolvingObject is PhonePkVote)
                {
                    var PhoneContent = progressPending.ResolvingObject as PhonePkVote;
                    XmlReader xtr = xdoc.CreateReader();
                    string currentElement = null;
                    while (xtr.Read())
                    {
                        switch (xtr.NodeType)
                        {
                            case XmlNodeType.Element:
                                {
                                    currentElement = xtr.LocalName;
                                    switch (xtr.LocalName)
                                    {
                                        case "resultinfo":
                                            {
                                                int result = 0; ;
                                                string resultmsg = "";
                                                int isgotologin = 0;
                                                while (xtr.MoveToNextAttribute())
                                                {
                                                    switch (xtr.Name)
                                                    {
                                                        case "result":
                                                            result = int.Parse(xtr.Value);
                                                            break;
                                                        case "resultmsg":
                                                            resultmsg = xtr.Value;
                                                            break;
                                                        case "isgotologin":
                                                            isgotologin = int.Parse(xtr.Value);
                                                            break;
                                                    }
                                                }
                                                if (result==0)
                                                {
                                                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                    {
                                                        PhoneContent.IsLoaded = false;
                                                        WaitUiThread.Set();
                                                    });
                                                    WaitUiThread.WaitOne();
                                                    progressPending.Stream.Dispose();
                                                    progressPending = null;
                                                    return;
                                                }
                                            }
                                            break;
                                    }
                                }
                                break;
                            case XmlNodeType.CDATA:
                            case XmlNodeType.Text:
                                switch (currentElement)
                                {
                                    case "breed":
                                        PhoneContent.Breed = int.Parse(xtr.Value);
                                        break;
                                    case "effect":
                                        PhoneContent.effect = int.Parse(xtr.Value);
                                        break;
                                    case "fece":
                                        PhoneContent.fece = int.Parse(xtr.Value);
                                        break;
                                    case "other":
                                        PhoneContent.other = int.Parse(xtr.Value);
                                        break;
                                    case "price":
                                        PhoneContent.price = int.Parse(xtr.Value);
                                        break;
                                    case "quality":
                                        PhoneContent.quality = int.Parse(xtr.Value);
                                        break;
                                }
                                break;
                        }
                    }//while end
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        progressPending.Stream.Dispose();
                        progressPending = null;
                        PhoneContent.IsLoaded = true;
                        WaitUiThread.Set();
                    });
                    WaitUiThread.WaitOne();
                   
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        private static void LoadPhoneTypeArea()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                XmlReader xtr = xdoc.CreateReader();
                if (progressPending.ResolvingObject is TypeArea)
                {
                    var PhoneContent = progressPending.ResolvingObject as TypeArea;
                  
                    string currentElement = null;
                    TypeAreaItem currentItem = null;
                        while (xtr.Read())
                        {
                            // Debug.WriteLine("NodeType is {0},{1},{2}", xtr.NodeType, xtr.LocalName, xtr.Value);
                            switch (xtr.NodeType)
                            {
                                case XmlNodeType.Element:
                                    {
                                        currentElement = xtr.LocalName;
                                        switch (xtr.LocalName)
                                        {
                                            case "resultinfo":
                                                {
                                                    int result = 0; ;
                                                    string resultmsg = "";
                                                    int isgotologin = 0;
                                                    while (xtr.MoveToNextAttribute())
                                                    {
                                                        switch (xtr.Name)
                                                        {
                                                            case "result":
                                                                result = int.Parse(xtr.Value);
                                                                break;
                                                            case "resultmsg":
                                                                resultmsg = xtr.Value;
                                                                break;
                                                            case "isgotologin":
                                                                isgotologin = int.Parse(xtr.Value);
                                                                break;
                                                        }
                                                    }
                                                    if (0 == result)
                                                    {
                                                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                        {
                                                            PhoneContent.Result = 1;
                                                           
                                                            WaitUiThread.Set();
                                                        });
                                                        WaitUiThread.WaitOne();
                                                        progressPending.Stream.Dispose();
                                                        progressPending = null;
                                                        //MessageBox.Show(resultmsg, "提示！", MessageBoxButton.OK);
                                                        return;
                                                    }//if end
                                                }
                                                break;
                                            case "page":
                                                while (xtr.MoveToNextAttribute())
                                                {
                                                    switch (xtr.Name)
                                                    {
                                                        case "total":
                                                            PhoneContent.TotalPage = int.Parse(xtr.Value);
                                                            break;
                                                        case "p":
                                                            PhoneContent.CurrentPage = int.Parse(xtr.Value);
                                                            if (PhoneContent.CurrentPage == 1)
                                                            {//从网络下载下来的才缓存
                                                                progressPending.Stream.Seek(0, SeekOrigin.Begin);
                                                                CacheImage(progressPending.Stream, progressPending.Uri);
                                                            }
                                                            break;
                                                    }
                                                }
                                                break;
                                            case "brand":
                                                currentItem = new TypeAreaItem();
                                                currentItem.Type = "Main";
                                                while (xtr.MoveToNextAttribute())
                                                {
                                                    switch (xtr.Name)
                                                    {
                                                        case "ppid":
                                                            currentItem.Ppid = xtr.Value;
                                                            break;
                                                        case "ppname":
                                                            currentItem.Ppname = xtr.Value;
                                                              break;
                                                        case "enname":
                                                            currentItem.Enname = xtr.Value;
                                                            break;
                                                        case "typeid":
                                                            currentItem.Typeid = xtr.Value;
                                                            break;
                                                        case "pnums":
                                                            currentItem.Pnums = xtr.Value;
                                                            break;
                                                    }
                                                }

                                                break;
                                        }
                                    }
                                    break;
                                case XmlNodeType.CDATA:
                                case XmlNodeType.Text:
                                    switch (currentElement)
                                    {
                                        case "logourl":
                                            if (currentItem != null)
                                            {
                                                currentItem.Logourl = xtr.Value;
                                            }
                                            break;
                                        
                                    }
                                    break;
                                case XmlNodeType.EndElement:
                                    if (xtr.LocalName == "brand")
                                    {
                                        //将其item添加进来
                                        if (currentItem != null)
                                        {
                                            currentItem.Type = "Main";
                                            progressPending.list.Add(currentItem);
                                            //PhoneContent.TypeAreaItems.Add(currentItem);
                                        }
                                    }
                                    break;
                            }
                        }//while end
                        if (PhoneContent.CurrentPage * PhoneContent.PageSize <= PhoneContent.TotalPage)
                        {
                            TypeAreaItem tailItem = new TypeAreaItem();
                            tailItem.Ppname = "正在加载...";
                            tailItem.Type = "Tail";
                            progressPending.list.Add(tailItem);
                            // PhoneContent.TypeAreaItems.Add(tailItem);
                        }
                       // PhoneContent.Result = 2;
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            if (PhoneContent.TypeAreaItems.Count == 0)
                            {
                                for (int i = 0; i < progressPending.list.Count; i++)
                                {
                                    PhoneContent.TypeAreaItems.Add((TypeAreaItem)progressPending.list[i]);
                                }
                            }
                            else
                            {
                                int position = 0;
                                //PhoneContent.TypeAreaItems.RemoveAt(PhoneContent.TypeAreaItems.Count - 1);
                                for (int i = 0; i < progressPending.list.Count; i++, position++)
                                {
                                    if (PhoneContent.TypeAreaItems.Count > position)
                                    {
                                        if (PhoneContent.TypeAreaItems [position].Ppid != ((TypeAreaItem)progressPending.list[position]).Ppid ||
                                           PhoneContent.TypeAreaItems [position].Pnums != ((TypeAreaItem)progressPending.list[position]).Pnums)
                                        {
                                            PhoneContent.TypeAreaItems[position]= (TypeAreaItem)progressPending.list[position];
                                        }
                                    }
                                    else
                                    {
                                        PhoneContent.TypeAreaItems.Add  ((TypeAreaItem)progressPending.list[position]);
                                    }
                                }
                                if (position < PhoneContent.TypeAreaItems.Count)
                                {
                                    for (int i = position; i < PhoneContent.TypeAreaItems.Count; )   
                                    {
                                        PhoneContent.TypeAreaItems.RemoveAt(i);
                                    }
                                }
                            }
                            progressPending.Stream.Dispose();
                            progressPending = null;
                            PhoneContent.Result = 2;
                            WaitUiThread.Set();
                            
                        });
                        WaitUiThread.WaitOne();
                }//if end
            }
            catch (Exception)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        private static void LoadPhoneTypeAreaMore()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                XmlReader xtr = xdoc.CreateReader();
                if (progressPending.ResolvingObject is TypeArea)
                {
                    var PhoneContent = progressPending.ResolvingObject as TypeArea;
                    
                    string currentElement = null;
                    TypeAreaItem currentItem = null;
                    if (PhoneContent.TypeAreaItems.Count != 0)
                    {
                       // PhoneContent.TypeAreaItems.RemoveAt(PhoneContent.TypeAreaItems.Count - 1);

                        while (xtr.Read())
                        {
                            switch (xtr.NodeType)
                            {
                                case XmlNodeType.Element:
                                    {
                                        currentElement = xtr.LocalName;
                                        switch (xtr.LocalName)
                                        {
                                            case "resultinfo":
                                                {
                                                    int result = 0; ;
                                                    string resultmsg = "";
                                                    int isgotologin = 0;
                                                    while (xtr.MoveToNextAttribute())
                                                    {
                                                        switch (xtr.Name)
                                                        {
                                                            case "result":
                                                                result = int.Parse(xtr.Value);
                                                                break;
                                                            case "resultmsg":
                                                                resultmsg = xtr.Value;
                                                                break;
                                                            case "isgotologin":
                                                                isgotologin = int.Parse(xtr.Value);
                                                                break;
                                                        }
                                                    }
                                                    if (0 == result)
                                                    {
                                                        MessageBox.Show(resultmsg, "提示！", MessageBoxButton.OK);
                                                        progressPending.Stream.Dispose();
                                                        progressPending = null;

                                                        return;
                                                    }//if end
                                                }
                                                break;
                                            case "page":
                                                while (xtr.MoveToNextAttribute())
                                                {
                                                    switch (xtr.Name)
                                                    {
                                                        case "total":
                                                            PhoneContent.TotalPage = int.Parse(xtr.Value);
                                                            break;
                                                        case "p":
                                                            PhoneContent.CurrentPage = int.Parse(xtr.Value);
                                                            break;
                                                    }
                                                }
                                                break;
                                            case "brand":
                                                currentItem = new TypeAreaItem();
                                                while (xtr.MoveToNextAttribute())
                                                {
                                                    switch (xtr.Name)
                                                    {
                                                        case "ppid":
                                                            currentItem.Ppid = xtr.Value;
                                                            break;
                                                        case "ppname":
                                                            currentItem.Ppname = xtr.Value;
                                                            break;
                                                        case "enname":
                                                            currentItem.Enname = xtr.Value;
                                                            break;
                                                        case "typeid":
                                                            currentItem.Typeid = xtr.Value;
                                                            break;
                                                        case "pnums":
                                                            currentItem.Pnums = xtr.Value;
                                                            break;
                                                    }
                                                }
                                                break;
                                        }
                                    }
                                    break;
                                case XmlNodeType.CDATA:
                                case XmlNodeType.Text:
                                    switch (currentElement)
                                    {
                                        case "logourl":
                                            if (currentItem != null)
                                            {
                                                currentItem.Logourl = xtr.Value;
                                            }
                                            break;

                                    }
                                    break;
                                case XmlNodeType.EndElement:
                                    if (xtr.LocalName == "brand")
                                    {
                                        //将其item添加进来
                                        if (currentItem != null)
                                        {
                                            currentItem.Type = "Main";
                                            progressPending.list.Add(currentItem);
                                        }
                                    }
                                    break;
                            }
                        }//while end
                        if (PhoneContent.CurrentPage * PhoneContent.PageSize < PhoneContent.TotalPage)
                        {
                            TypeAreaItem tailItem = new TypeAreaItem();
                            tailItem.Ppname = "正在加载...";
                            tailItem.Type = "Tail";
                            progressPending.list.Add(tailItem);
                            //PhoneContent.TypeAreaItems.Add(tailItem);
                        }

                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            PhoneContent.TypeAreaItems.RemoveAt

        (PhoneContent.TypeAreaItems.Count - 1);

                            for (int i = 0; i < progressPending.list.Count; i++)
                            {
                                PhoneContent.TypeAreaItems.Add

    ((TypeAreaItem)progressPending.list[i]);
                            }

                            progressPending.Stream.Dispose();
                            progressPending = null;
                            PhoneContent.Result = 2;
                            WaitUiThread.Set();
                        });
                        WaitUiThread.WaitOne();
                    }
                }
            }
            catch (Exception)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
            }
        }
        private static void LoadRegisterAccount()
        {
            XDocument xdoc = null;
            try
            {
                xdoc = XDocument.Load(progressPending.Stream);
            }
            catch (Exception)
            { }
            if (xdoc == null)
            {
                progressPending.Stream.Dispose();
                progressPending = null;
                return;
            }
            if (progressPending.ResolvingObject is RegisteAccount)
             {
                 var PhoneContent = progressPending.ResolvingObject as RegisteAccount;
                 try 
                 {
                     foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
                     {
                         //如果有错弹出错误处理;
                         int result = int.Parse(element.Attribute("result").Value);
                         PhoneContent.ResultMsg = element.Attribute("resultmsg").Value;
                         //PhoneContent. = int.Parse(element.Attribute("isgotologin").Value);
                         if (0 == result)
                         {
                             //MessageBox.Show(resultmsg, "加载更多内容失败", MessageBoxButton.OK);
                             Deployment.Current.Dispatcher.BeginInvoke(() =>
                             {
                                 PhoneContent.Result = 1;
                                 WaitUiThread.Set();
                             });
                             WaitUiThread.WaitOne();
                             progressPending.Stream.Dispose();
                             progressPending = null;
                            
                             return;
                         }//if end

                     }
                     foreach (XElement element in xdoc.Descendants("lexun"))
                     {
                         Deployment.Current.Dispatcher.BeginInvoke(() =>
                         {
                             PhoneContent.Userid = int.Parse(element.Element("userid").Value);
                             PhoneContent.Userrank = int.Parse(element.Element("userrank").Value);
                             PhoneContent.Viprank = int.Parse(element.Element("viprank").Value);
                             PhoneContent.Lxt = element.Element("lxt").Value;
                             PhoneContent.Nick = element.Element("nick").Value;
                             PhoneContent.Sex = element.Element("sex").Value;
                             PhoneContent.Sign = element.Element("sign").Value;
                             PhoneContent.Vipimgurl = element.Element("vipimgurl").Value;
                             PhoneContent.Headimg = element.Element("headimg").Value;
                             WaitUiThread.Set();
                         });
                         WaitUiThread.WaitOne();
                     }


                   
                     Deployment.Current.Dispatcher.BeginInvoke(() =>
                     {
                         PhoneContent.Result = 2;//成功写入2
                         
                         progressPending.Stream.Dispose();
                         progressPending = null;
                         WaitUiThread.Set();
                     });
                     WaitUiThread.WaitOne();
                 }
                 catch(Exception e)
                 {
                     Debug.WriteLine(e.Message);
                     progressPending.Stream.Dispose();
                     progressPending = null;
                     Deployment.Current.Dispatcher.BeginInvoke(() =>
                     {
                         PhoneContent.ResultMsg = e.Message;
                         PhoneContent.Result = 1;
                         WaitUiThread.Set();
                     });
                     WaitUiThread.WaitOne();
                     
                 }
                 
                
             }
        }
        private static void LoadPhoneShowDownload()
        {
            try
            {
                XDocument xdoc = null;
                try
                {
                    xdoc = XDocument.Load(progressPending.Stream);
                }
                catch (Exception)
                { }
                if (xdoc == null)
                {
                    progressPending.Stream.Dispose();
                    progressPending = null;
                    return;
                }
                if (progressPending.ResolvingObject is ShowDownloadView)
                {

                    var PhoneInfoCenter = progressPending.ResolvingObject as ShowDownloadView;

                    foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
                    {
                        //如果有错弹出错误处理;
                        int result = int.Parse(element.Attribute("result").Value);
                        string resultmsg = element.Attribute("resultmsg").Value;
                        int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
                        if (0 == result)
                        {
                            PhoneInfoCenter.Result = 1;
                            PhoneInfoCenter.ResultMsg = resultmsg;
                        }
                    }
                    foreach (XElement element in xdoc.Element("lexun").Descendants("page"))
                    {

                        PhoneInfoCenter.TotalPage = int.Parse(element.Attribute("total").Value);
                        PhoneInfoCenter.CurrentPage = int.Parse(element.Attribute("p").Value);
                    }
                    if (PhoneInfoCenter.CurrentPage == 1)
                    {//只有第一页会缓存其余的页数都不会缓存
                        progressPending.Stream.Seek(0, SeekOrigin.Begin);
                        CacheImage(progressPending.Stream, progressPending.Uri);
                    }
                    foreach (XElement element in xdoc.Element("lexun").Descendants("adinfo"))
                    {
                        ShowDownloadItem item = new ShowDownloadItem();
                        item.Type = "Main";
                        item.Appid = int.Parse(element.Attribute("appid").Value);
                        item.Downcount = int.Parse(element.Attribute("downcount").Value);
                        item.Isfee = int.Parse(element.Attribute("isfee").Value);
                        item.Score = int.Parse(element.Attribute("score").Value);
                        item.Position = int.Parse(element.Attribute("position").Value);
                        item.Urltype = int.Parse(element.Attribute("urltype").Value);
                        item.Integral = int.Parse(element.Attribute("integral").Value);
                        item.Checkscore = int.Parse(element.Attribute("checkscore").Value);
                        item.Isad = int.Parse(element.Element("isad").Value);
                        item.Addtime = element.Attribute("addtime").Value;
                        item.Filesize = element.Attribute("filesize").Value;
                        item.Title = element.Element("title").Value;
                        item.Filename = element.Element("filename").Value;
                        item.Icon = element.Element("icon").Value;
                        //
                        progressPending.list.Add(item);
                        //PhoneInfoCenter.TypeShowDownLoadItems.Add(item);
                    }
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        if (PhoneInfoCenter.TypeShowDownLoadItems.Count == 0)
                        {
                            for (int i = 0; i < progressPending.list.Count; i++)
                            {
                                PhoneInfoCenter.TypeShowDownLoadItems.Add

((ShowDownloadItem)progressPending.list[i]);
                            }

                        }
                        else
                        {
                            int position = 0;
                           
                            for (int i = 0; i < progressPending.list.Count; i++,

position++)
                            {
                                if (PhoneInfoCenter.TypeShowDownLoadItems.Count >

position)
                                {
                                    if (PhoneInfoCenter.TypeShowDownLoadItems

[position].Appid != ((ShowDownloadItem)progressPending.list[position]).Appid )
                                    {
                                        PhoneInfoCenter.TypeShowDownLoadItems[position]

= (ShowDownloadItem)progressPending.list[position];
                                    }
                                }
                                else
                                {
                                    PhoneInfoCenter.TypeShowDownLoadItems.Add

((ShowDownloadItem)progressPending.list[position]);
                                }

                            }
                            if (position < PhoneInfoCenter.TypeShowDownLoadItems.Count)
                            {
                                for (int i = position; i <

PhoneInfoCenter.TypeShowDownLoadItems.Count; )
                                {
                                    PhoneInfoCenter.TypeShowDownLoadItems.RemoveAt(i);
                                }
                            }
                        }
                        progressPending.Stream.Dispose();
                        progressPending = null;

                        PhoneInfoCenter.Result = 2;
                        WaitUiThread.Set();
                    });
                    WaitUiThread.WaitOne();
                }
               
            }
            catch(Exception)
            {

            }
        }
        private static void LoadPhoneShowDownloadMore()
        {
            //try
            //{
            //    XDocument xdoc = XDocument.Load(pendingCompletion.Stream);
               
            //    if (pendingCompletion.ResolvingObject is ShowDownloadView)
            //    {
            //        var PhoneInfoCenter = pendingCompletion.ResolvingObject as ShowDownloadView;
            //        if (PhoneInfoCenter.TypeShowDownLoadItems.Count == 0)
            //        {
            //            return;
            //        }
            //        PhoneInfoCenter.TypeShowDownLoadItems.RemoveAt(PhoneInfoCenter.TypeShowDownLoadItems.Count-1);
            //        //
            //        foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
            //        {
            //            //如果有错弹出错误处理;
            //            int result = int.Parse(element.Attribute("result").Value);
            //            string resultmsg = element.Attribute("resultmsg").Value;
            //            int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
            //            if (0 == result)
            //            {
            //                PhoneInfoCenter.Result = 1;
            //                PhoneInfoCenter.ResultMsg = resultmsg;
            //            }
            //        }
            //        foreach (XElement element in xdoc.Element("lexun").Descendants("page"))
            //        {

            //            PhoneInfoCenter.TotalPage = int.Parse(element.Attribute("total").Value);
            //            PhoneInfoCenter.CurrentPage = int.Parse(element.Attribute("p").Value);
            //        }
            //        foreach (XElement element in xdoc.Element("lexun").Descendants("adinfo"))
            //        {
            //            ShowDownloadItem item = new ShowDownloadItem();
            //            item.Type = "Main";
            //            item.Appid = int.Parse(element.Attribute("appid").Value);
            //            item.Downcount = int.Parse(element.Attribute("downcount").Value);
            //            item.Isfee = int.Parse(element.Attribute("isfee").Value);
            //            item.Score = int.Parse(element.Attribute("score").Value);
            //            item.Position = int.Parse(element.Attribute("position").Value);
            //            item.Urltype = int.Parse(element.Attribute("urltype").Value);
            //            item.Integral = int.Parse(element.Attribute("integral").Value);
            //            item.Checkscore = int.Parse(element.Attribute("checkscore").Value);
            //            item.Isad = int.Parse(element.Element("isad").Value);
            //            item.Addtime = element.Attribute("addtime").Value;
            //            item.Filesize = element.Attribute("filesize").Value;
            //            item.Title = element.Element("title").Value;
            //            item.Filename = element.Element("filename").Value;
            //            item.Icon = element.Element("icon").Value;
            //            PhoneInfoCenter.TypeShowDownLoadItems.Add(item);
            //        }
            //        if (PhoneInfoCenter.CurrentPage * PhoneInfoCenter.PageSize <= PhoneInfoCenter.TotalPage)
            //        {
            //            ShowDownloadItem tailItem = new ShowDownloadItem();
            //            tailItem.Type = "Tail";
            //            tailItem.Filename = "加载更多...";
            //            PhoneInfoCenter.TypeShowDownLoadItems.Add(tailItem);
            //        }
            //    }
            //}
            //catch(Exception)
            //{

            //}
                
        }
        private static void LoadPhoneDownloadItem()
        {
            //try
            //{
            //    XDocument xdoc = XDocument.Load(pendingCompletion.Stream);

            //    if (pendingCompletion.ResolvingObject is ConversationObject)
            //    {
            //        var PhoneInfoCenter = pendingCompletion.ResolvingObject as ConversationObject;
            //        foreach (XElement element in xdoc.Element("lexun").Descendants("resultinfo"))
            //        {
            //            //如果有错弹出错误处理;
            //            int result = int.Parse(element.Attribute("result").Value);
            //            string resultmsg = element.Attribute("resultmsg").Value;
            //            int isgotologin = int.Parse(element.Attribute("isgotologin").Value);
            //            if (0 == result)
            //            {
            //                PhoneInfoCenter.Result = 1;
            //                PhoneInfoCenter.ResultMsg = resultmsg;
            //            }
            //        }
            //        DowloadManagerItem item = new DowloadManagerItem();
            //        foreach (XElement element in xdoc.Element("lexun").Descendants("content"))
            //        {
            //            item.Type = "ready";
            //            item.Appid = element.Element("appid").Value;
            //            item.Title = element.Element("title").Value;
            //            item.Downcount = int.Parse(element.Element("downcount").Value);
            //            item.Score = int.Parse(element.Element("score").Value);
            //            item.Isfee = int.Parse(element.Element("isfee").Value);
            //            item.Icon = element.Element("icon").Value;
            //            item.Addtime = element.Element("addtime").Value;
            //            item.Remark = element.Element("remark").Value;
            //            item.Downurl = element.Element("downurl").Value;
            //            item.Filesize = element.Element("filesize").Value+"MB";
            //            item.HasFilesize = 0;
            //            item.TotalSize = 0;
            //            item.Result = 0;
            //        }
            //        PhoneInfoCenter.Item.Add(item);
            //        PhoneInfoCenter.Result = 2;
            //    }
            //}
            //catch (Exception e)
            //{
            //    Debug.WriteLine(e.Message);
            //}
        }
        private static void ParseXml()
        {
                //这里可以使用委托来优化不用写的这么麻烦  
                if (progressPending.ResolvingObject is PhoneInfoCenterView)
                        {
                            var phoneInfo = progressPending.ResolvingObject as PhoneInfoCenterView;
                            if (phoneInfo.AllowAdd == false)
                            {//下载
                                if (phoneInfo.ClassNmae == "more")
                                {
                                    LoadFirstPhoneInfoMorePage();
                                }
                                else
                                {
                                    LoadFirstPhoneInfoCenterPage();
                                }
                             
                            }
                            else
                            {//追加
                                phoneInfo.AllowAdd = false;
                                AddPhoneInfoCenterPage();

                            }
                        }
                
              
                else if (progressPending.ResolvingObject is Image)
                        {
                            //if has been cached,do not cache
                            if (!IsImageCached(progressPending.Uri))
                            {
                                if (progressPending.Uri.IsAbsoluteUri)
                                {
                                    if (progressPending.Uri.AbsoluteUri == "http://sj.lexun.com/phone_upload/rc_pic/zixun/490854/lx_0_490854.jpg")
                                    {
                                        Debug.WriteLine("I am find it");
                                    }
                                    CacheImage(progressPending.Stream, progressPending.Uri);
                                    progressPending.Stream.Seek(0, SeekOrigin.Begin);
                                }
                                
                            }
                           
                      Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                try
                                {

                                    ImageSource bitmap;
                                    var bitmapImage = new BitmapImage();
                                    bitmapImage.CreateOptions = BitmapCreateOptions.BackgroundCreation;
                                    if (progressPending.Stream.Length == 0)
                                    {
                                        var sriSystem = Application.GetResourceStream(new Uri("Icon/defaultIcon.png", UriKind.RelativeOrAbsolute));
                                        bitmapImage.SetSource(sriSystem.Stream);
                                        ((Image)progressPending.ResolvingObject).Stretch = Stretch.Uniform;
                                        sriSystem.Stream.Dispose();
                                    }
                                    else
                                    {
                                        bitmapImage.SetSource(progressPending.Stream);
                                        bitmap = bitmapImage;
                                        ((Image)progressPending.ResolvingObject).Source = bitmap;
                                        ((Image)progressPending.ResolvingObject).Stretch = ImageStrech;
                                    }
                                }

                                catch (Exception e)
                                {
                                    Debug.WriteLine(e.Message);
                                    progressPending = null;
                                }
                                WaitUiThread.Set();
                                
                            });
                      WaitUiThread.WaitOne();
                        }
               
            
                else if (progressPending.ResolvingObject is PhoneInfoContentView)
                        {
                            if (((PhoneInfoContentView)progressPending.ResolvingObject).ClassNmae == "phoneInfoContent")
                            {
                                if (((PhoneInfoContentView)progressPending.ResolvingObject).AllowAdd == true)
                                {
                                    ((PhoneInfoContentView)progressPending.ResolvingObject).AllowAdd = false;
                                    LoadMorePhoneContent();
                                }
                                else
                                {
                                    LoadFirstPhoneContent();
                                }

                            }
                             else if (((PhoneInfoContentView)progressPending.ResolvingObject).ClassNmae == "phoneInfoReply")
                            {
                                //这里还会分是否追加新的评论内容的情况
                                if (((PhoneInfoContentView)progressPending.ResolvingObject).AllowAdd == true)
                                {
                                    ((PhoneInfoContentView)progressPending.ResolvingObject).AllowAdd = false;
                                    LoadMorePhoneReply();
                                }
                                else
                                {
                                    LoadFirstPhoneReply();
                                    //((PhoneInfoContentView)pendingCompletion.ResolvingObject).text.Text = ((PhoneInfoContentView)pendingCompletion.ResolvingObject).TotalPage.ToString();
                                }

                            }
                        }
                        else if (progressPending.ResolvingObject is ReplyResult)
                        {
                            LoadReplyResult();
                        }
                        else if (progressPending.ResolvingObject is ShrewdEyeView)
                        {
                            LoadShrewdEye();
                        }
                        else if (progressPending.ResolvingObject is ScoreDetail)
                        {
                            LoadScoreDetail();
                        }
                        else if (progressPending.ResolvingObject is SearchResultView)
                        {
                            //
                            if (((SearchResultView)progressPending.ResolvingObject).AllowAdd == true)
                            {
                                ((SearchResultView)progressPending.ResolvingObject).AllowAdd = false;
                                LoadMoreSearchResult();
                            }
                            else
                            {
                                if (((SearchResultView)progressPending.ResolvingObject).ClassName == "selfResult")
                                {
                                    LoadInitResult();
                                }
                                else
                                {
                                    LoadFirstSearchResult();
                                }

                                //((PhoneInfoContentView)pendingCompletion.ResolvingObject).text.Text = ((PhoneInfoContentView)pendingCompletion.ResolvingObject).TotalPage.ToString();
                            }

                        }
                        else if (progressPending.ResolvingObject is phonePkView)
                        {
                            //加载默认的机型PK
                            LoadDefualtPhonePK();

                        }
                        else if (progressPending.ResolvingObject is TypeParameter)
                        {
                            //加载默认的参数
                            LoadTypeParameter();
                        }
                        else if (progressPending.ResolvingObject is TypePrice)
                        {
                            TypePrice tp = progressPending.ResolvingObject as TypePrice;
                            if (tp == null)
                            {
                                return;
                            }
                            if (tp.AllowAdd == true)
                            {
                                tp.AllowAdd = false;
                                LoadMoreTypePrice();
                            }
                            else
                            {
                                LoadTypePrice();
                            }
                        }
                        else if (progressPending.ResolvingObject is TypePicture)
                        {
                            TypePicture tp = progressPending.ResolvingObject as TypePicture;
                            if (tp == null)
                            {
                                return;
                            }
                            LoadTypePicture();

                        }
                        else if (progressPending.ResolvingObject is TypeCommentView)
                        {
                            TypeCommentView tp = progressPending.ResolvingObject as TypeCommentView;
                            if (tp == null)
                            {
                                return;
                            }
                            if (tp.AllowAdd == true)
                            {
                                tp.AllowAdd = false;
                                LoadMoreTypeComment();
                            }
                            else
                            {
                                LoadTypeComment();
                            }
                        }
                        else if (progressPending.ResolvingObject is BibleView)
                        {
                            BibleView tp = progressPending.ResolvingObject as BibleView;
                            if (tp == null)
                            {
                                return;
                            }
                            if (tp.AllowAdd == true)
                            {
                                tp.AllowAdd = false;
                                LoadMoreTypeBible();
                            }
                            else
                            {
                                LoadTypeBible();
                            }
                        }
                        else if (progressPending.ResolvingObject is PhonePkDetail)
                        {
                            PhonePkDetail tp = progressPending.ResolvingObject as PhonePkDetail;
                            if (tp == null)
                            {
                                return;
                            }
                            //
                            LoadPhonePkParameter();

                        }
                        else if (progressPending.ResolvingObject is PhonePkVote)
                        {
                            LoadPhonePkVote();
                        }
                        else if (progressPending.ResolvingObject is TypeArea)
                        {
                            TypeArea ta = progressPending.ResolvingObject as TypeArea;
                            if (ta == null)
                            {
                                return;
                            }
                            if (ta.AllowAdd == true)
                            {
                                ta.AllowAdd = false;
                                LoadPhoneTypeAreaMore( );
                            }
                            else
                            {
                                LoadPhoneTypeArea( );
                            }

                        }
                        else if (progressPending.ResolvingObject is RegisteAccount)
                        {
                            LoadRegisterAccount( );
                        }
                        else if (progressPending.ResolvingObject is ShowDownloadView)
                        {
                            ShowDownloadView ta = progressPending.ResolvingObject as ShowDownloadView;
                            if (ta == null)
                            {
                                return;
                            }
                            if (ta.AllowAdd == true)
                            {
                                ta.AllowAdd = false;
                                LoadPhoneShowDownloadMore( );

                            }
                            else
                            {
                                LoadPhoneShowDownload( );
                            }
                        }
                        else if (progressPending.ResolvingObject is ConversationObject)
                        {

                            LoadPhoneDownloadItem( );
                        }//
      
                      //progressPending.Stream.Dispose();
                    }
    }
}
